Trying again without all the nasty HTML -- apologies to all. [David Abrahams] > . . . I want to put in another plug for itemize(), Well, since we're doing post-Pronouncement fantasizing . . . here's one more plug for "itemize". Noting that for k,v in adict.iteritems(): is probably as useful as for i,v in enumerate(aseq): why not change the spec to: >>> def itemize(iterable): ... # use iteritems if defined ... try: ... for item in iterable.iteritems(): yield item ... except AttributeError: pass ... # and then everything as before ... i = 0 ... iterator = iter(iterable) ... while 1: ... yield i,iterator.next() ... i += 1 ... So "itemize(iterable)" returns an iterator that yields (k,v) pairs from the iterable.iteritems() method if defined, else pairs generated by associating 0,1,...,n-1 with n values from iter(iterable). This allows for k,v in itemize(adict_or_aseq): to be written uniformly for dicts and seqs. And makes list(itemize(adict)) == adict.items() work, removing one of the objections to the name "itemize". Also, if one were to need, for example, a sequence whose indices start at 1 instead of 0, one could define a sequence class that implements iteritems and objects of said class would work just fine with "itemize". Jim
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