filter()ing a dict
Duncan Booth
duncan at NOSPAMrcp.co.uk
Thu Aug 7 10:53:47 EDT 2003
"John Roth" <newsgroups at jhrothjr.com> wrote in
news:vj4p5t8l96201 at news.supernews.com:
> According to the doc, filter() processes sequences,
> iterators and objects that support the iterator protocol.
> A dict is none of those things, unless it supports the iterator
> protocol, which is not mentioned in the documentation
> as of 2.2.3. Possibly it does in 2.3.0.
It looks to me like there is a hole in the Python documentation. The
"what's new in Python 2.2" said:
> Iterator support has been added to some of Python's basic types.
> Calling iter() on a dictionary will return an iterator which loops
> over its keys:
However, the library reference documentation for mapping types doesn't seem
to mention that dictionaries support the iterator protocol directly,
although it does mention the explicit ways to get iterators out of
dictionaries (such as iteritems()).
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list