[Tutor] Iterating a dict with an iteration counter? How would *you* do it?
Dave Angel
davea at davea.name
Mon Feb 4 23:26:31 CET 2013
On 02/04/2013 12:58 PM, Modulok wrote:
> Hmm.. no kidding. Well, at least I knew I was over-complicating it.
>
> Cheers!
> -Modulok-
>
>
Please don't top-post.
Another point. I don't currently have Python 3.x installed, but I seem
to remember that in Python 3 you can use the dict itself as an iterator
providing both key and value. If I'm right, then it could be simplified
further to:
for i, (k, v) in enumerate(data):
A simple test will prove me right or wrong.
--
DaveA
More information about the Tutor
mailing list