Loading ...
Sorry, an error occurred while loading the content.

183RE: [python-iter] Digest Number 21

Expand Messages
  • Greg Wilson
    Mar 14, 2001
    • 0 Attachment
      I 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:

      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,
      Greg

      p.s. I actually have a lot of code like that above, since
      I use lists for dense vectors, and dicts for sparse
      vectors.
    • Show all 6 messages in this topic