If I have:
d = {\'one\':1, \'two\':2, \'three\':3, \'four\':4}
How can I get values of \'one\' and \'three\' in one command. Something like thi
You can just directly access them:
>>> d = {'one':1, 'two':2, 'three':3, 'four':4}
>>> [d['one'], d['three']]
[1, 3]
>>>
In the method you use, it is searching for the key ('one', 'three')
in d
, which obviously doesn't exist.
Using list comprehension:
>>> d = {'one':1, 'two':2, 'three':3, 'four':4}
>>> [d[key] for key in 'one', 'three']
[1, 3]