# PEP Proposal: list.first() and list.last() for accessing most important list elements

**URL:** <https://discuss.python.org/t/pep-proposal-list-first-and-list-last-for-accessing-most-important-list-elements/64532>\
**Category:** Ideas\
**Created:** [September 20, 2024, 3:48pm UTC](https://discuss.python.org/t/pep-proposal-list-first-and-list-last-for-accessing-most-important-list-elements/64532 "2024-09-20T15:48:45Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![bschubert](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bschubert/32/26920_2.png) [@bschubert](https://discuss.python.org/u/bschubert)\
**Post date:** [September 20, 2024, 6:37pm UTC](https://discuss.python.org/t/pep-proposal-list-first-and-list-last-for-accessing-most-important-list-elements/64532/9 "2024-09-20T18:37:14Z")

</div>

Somewhat related:

> [@Add safe \`.get\` method to List](https://discuss.python.org/t/add-safe-get-method-to-list/32555):
>
> To access an item in a dictionary, you use indexing: d["some\_key"]. However, if the key doesn’t exist in the dictionary, a KeyError is raised. To avoid this, you can use .get and pass in a default value to return instead: d.get("some\_key", "default value"). Lists don’t have such a method for safely indexing. There are many ways around it (as documented in many SO threads: [thread 1](https://stackoverflow.com/questions/5125619/why-doesnt-list-have-safe-get-method-like-dictionary), [thread 2](https://stackoverflow.com/questions/2492087/how-to-get-the-nth-element-of-a-python-list-or-a-default-if-not-available)), but they’re all pretty awkward and they aren’t composable or chain-able the same way that .get() is. T…

---

_[View the full topic](https://discuss.python.org/t/pep-proposal-list-first-and-list-last-for-accessing-most-important-list-elements/64532)._
