First page Back Continue Last page Overview Graphics

Converting Dictionaries into Lists

Python2:

>>> w={"house":"Haus",

"cat":"Katze","red":"rot"}

>>> w.items()

[('house', 'Haus'), ('red', 'rot'), ('cat', 'Katze')]

>>> w.keys()

['house', 'red', 'cat']

>>> w.values()

['Haus', 'rot', 'Katze']

>>> w.iteritems()

<dictionary-itemiterator object at 0x7f877966c470>

>>> w.iterkeys()

<dictionary-keyiterator object at 0x7f877966c4c8>

>>> w.itervalues()

<dictionary-valueiterator object at 0x7f877966c470>

>>>

Python3:

>>> w={"house":"Haus",

"cat":"Katze","red":"rot"}

>>> w.items()

dict_items([('house', 'Haus'), ('red', 'rot'), ('cat', 'Katze')])

>>> list(w.items())

[('house', 'Haus'), ('red', 'rot'), ('cat', 'Katze')]

>>> w.keys()

dict_keys(['house', 'red', 'cat'])

>>> list(w.keys())

['house', 'red', 'cat']

>>> w.values()

dict_values(['Haus', 'rot', 'Katze'])