Python赋值破坏

标签 python

如何在 Python 中进行 ES6 类型的对象解构?

dictionary = {}

dictionary['a'] = 'hello'
dictionary['b'] = 'goodbye'

print dictionary

a, b = [dictionary]

print a, b

如何让它打印 hello goodbye

最佳答案

你实际上可以这样做:

a, b = dictionary.values()

或者如果你担心字典没有排序,你可以这样做:

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

关于Python赋值破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41216078/

相关文章:

python - 如何在 Cython 中使用 openMP 之类的东西?

python - 使用 threading.Thread.join()

python - 如何在 Python 中验证具有多个命名空间的 XML?

python - 安装 Python 请求

python - 根据不同大小的数组 Y 的条件屏蔽数组 X

python - 如何获取特定列表元素的平均值

python - FilePath 宏不包含 Pycharm 中的值

javascript - 如何使用字典从 python 中提取嵌套的 JSON 值?

python - 从 Python 运行 SQL 'Kill'

python - 鼻测试无法找到请求包