A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-October/093403.html below:

[Python-Dev] Retrieve an arbitrary element from a set without removing it

[Python-Dev] Retrieve an arbitrary element from a set without removing itAlexander Belopolsky alexander.belopolsky at gmail.com
Tue Oct 27 18:50:56 CET 2009
On Tue, Oct 27, 2009 at 1:33 PM, Chris Bergstresser <chris at subtlety.com> wrote:
> On Tue, Oct 27, 2009 at 11:06 AM, Georg Brandl <g.brandl at gmx.net> wrote:
>> Sorry to nitpick, but there is no list.get().
>
>   No?  How ... odd.

Odd indeed.  My first reaction was: it is not needed because lists
support slicing, but when I tried to construct a list.get() using
slicing the best I could come up with was the following hack

>>> def lget(l, i, v):  return (l[i:] or [v])[0]
...
>>> lget(range(10), 20, 200)
200
>>> lget(range(10), 5, 50)
5

Yet for some reason I never missed this functionality ...
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4