185Re: [python-iter] Digest Number 21
- Mar 14, 2001
> I agree that having "blah in dict" iterate over/checkThere isn't. The question may be meaningless (e.g. if 'x' is a tree).
> 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:
> def column(x):
> 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)?
> Thanks,Wrap your different representations in a class that presents a uniform
> p.s. I actually have a lot of code like that above, since
> I use lists for dense vectors, and dicts for sparse
--Guido van Rossum (home page: http://www.python.org/~guido/)
- << Previous post in topic Next post in topic >>