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-April/044166.html below:

[Python-Dev] Proposed iterator representations

[Python-Dev] Proposed iterator representationsRaymond Hettinger python at rcn.com
Thu Apr 8 22:37:18 EDT 2004
I checked in two itertool representations that were clear-cut:

>>> from itertools import count, repeat
>>> count(20)
count(20)
>>> repeat(None, 12)
repeat(None, 12)



For xrange iterators, there are a few choices:

>>> it = iter(xrange(10, 20, 2))
iter(xrange(10, 20, 2))
     or
rangeiterator(10, 20, 2)
     or
<rangeiterator start=10, stop=20, step=2>

The first is my favorite.  Though odd looking, it can be run through
eval() and is completely self-documenting.  The second has the virtue of
using the actual type name but it cannot be run through eval().  The
third is closer to the current format but adds some information.


For dictionaries, lists, tuples, and reversed, there are similar choices
but the eval() version can only be supported with a full listing of the
parent object:

>>> iter(dict(a=1, b=2, c=3, d=4, e=5))
iter(dict.fromkeys(['a', 'c', 'b', 'e', 'd']))
     or
<dictionary-keyiterator object:  'a', 'c', 'b', ...>


>>> dict(a=1, b=2, c=3, d=4, e=5).iteritems()
dict([('a', 1), ('c', 3), ('b', 2), ('e', 5), ('d', 4)]).iteritems()
     or
<dictionary-itemiterator object:  ('a', 1), ('c', 3), ('b', 2) ...>


>>> reversed('abcde')
reversed(['a', 'b', 'c', 'd', 'e'])
     or
<reversed object:  'e', 'd', 'c', ...>


What do you guys think?



Raymond Hettinger


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