Wednesday, 29 May 2013

Python - Dictionary to List with Key only

Dictionary
key_and_item = dict([(x,0) for x in range(10)])
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0}

List
key_only = list(key_and_item)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# OrderedDict will also have the same effect

No comments :

Post a Comment