How to iterate throuhg dictionary

Steve Holden sholden at
Wed Aug 8 13:58:57 CEST 2001

"Piotr Legiecki" <piotrlg at> wrote in message
news:9kqvaa$tbl$1 at
> Hi
> I'v created dictionary named d={}. Its structure is like this:
> {key, [list]}
> I'd like to print all values stored in  'd'. What is the easiest way to do
> it?

Well, of course,

    print d

will do it! I imagine you are looking for something more elaborate? You can
return the keys, the values, or the (key, value) item pairs from a
dictionary with its methods d.keys(), d.values() and d.items().

So another way would be ...

for k, v in d.items():
    print k, ":", ", ".join(v)

which actually won't give you anything too much different!


More information about the Python-list mailing list