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/2004-July/045875.html below:

[Python-Dev] PEP 276 (simple iterator for ints)

[Python-Dev] PEP 276 (simple iterator for ints) [Python-Dev] PEP 276 (simple iterator for ints)Delaney, Timothy C (Timothy) tdelaney at avaya.com
Mon Jul 5 01:31:10 CEST 2004
Andrew Koenig wrote:

> for i in myList.keys():
> 
> would be even better, because it allow the same usage for dict and
> list.  Of course that wouldn't generalize to other sequences that
> support len. 

Hmm - time to propose a new builtin (can't remember this being proposed
before, though I know we've discussed adding keys() to lists).

keys(mapping)

Returns an iterator of the keys of the mapping. For any sequence that
implements __len__, returns an iterator of the integers 0..__len__. For
any object that implements keys() or iterkeys(), returns the appropriate
iterator.

I would also suggest that __keys__ might be a useful magic method.

There might be a use for values(mapping) as well, but I don't think it's
as useful.

Tim Delaney

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