How can I do the ES6 type object destructuring in Python?
dictionary = {}
dictionary['a'] = 'hello'
dictionary['b'] = 'goodbye'
print dictionary
a, b = [dictionary]
print a, b
How can I have it print hello goodbye ?
You can actually do this:
a, b = dictionary.values()
Or if you are worrying dictionary is not ordered, you can do:
from collections import OrderedDict
print "Hello World!\n"
dictionary = OrderedDict() # <-------------
dictionary['a'] = 'hello'
dictionary['b'] = 'goodbye'
print dictionary
a, b = dictionary.values()
print a, b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With