183RE: [python-iter] Digest Number 21
- Mar 14, 2001I agree that having "blah in dict" iterate over/check
keys, rather than the values, is the natural behavior.
I even think I know how to explain it to newcomers.
What I don't know is how to write a polymorphic function
to iterate over an arbitrary container, since:
for i in x:
print i, "\t", x[i]
doesn't work. Given an arbitrary object 'x', is there
some way for me to tell whether its iterator is generating
indices or values (or both)?
p.s. I actually have a lot of code like that above, since
I use lists for dense vectors, and dicts for sparse
- Next post in topic >>