Python – Convert a Dictionary to a List

Code — Tags: — Mark @ 9:53 pm

We can easily create a Python list by pulling only the values out of a dictionary. This is done via the values() method.


>>> x = {'a':1, 'b':2}
>>> x
{'a': 1, 'b': 2}
>>> y = list(x.values())
>>> y
[(1), (2)

blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2010 Mark Stahler – Blog | powered by WordPress with Barecity