Dictionaries, popitem() method example
Steve Holden
sholden at holdenweb.com
Thu Nov 1 07:22:13 EST 2001
"Antonios B. Kaklis" <antoni3 at otenet.gr> wrote ...
> Hello to everybody...'
Hello
> There is something that i' don't understand.
> In the Python Library Reference, Section 2.1.6 "Mapping Types"
> It says: "a.popitem( )" --->Note 6: Is useful to destructively iterate
over
> a dictionary as often
> used in set algorithms!
>
> I don't understand 1) what is "Destructively iteration over a dictionary"
This simply means that the item returned by popitem() no longer exists in
the dictionary. So if you popitem() enough you will have destryoed it (left
it empty - it's still a dictionary)!
> 2) Set Algotithms
Algorithms that treat the items in the dictionary as a set! The dictionary
is a natural structure for this since the presence of an item under a
particular key is easily detected, and a key is either present or not.
regards
Steve
--
http://www.holdenweb.com/
More information about the Python-list
mailing list