filter()ing a dict

Sean Ross sross at connectmail.carleton.ca
Thu Aug 7 10:49:04 EDT 2003


"John Roth" <newsgroups at jhrothjr.com> wrote in message
news:vj4p5t8l96201 at news.supernews.com...
> 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.


d =  {"key 1": ["value 1", "value 2", "value 3", "value 4"],
      "key 2": ["value 1", "value 2"],
      "key 3": ["value2", "value 3", "value 4"],
      "key 4": ["value 1", "value 2", "value 3", "value 4"]}

# dict is an iterator that returns its keys
for key in d:
    print key

# output
key 1
key 2
key 3
key 4






More information about the Python-list mailing list