如何在 Python 中将集合转换为列表?使用
a = set(["Blah", "Hello"])
a = list(a)
不起作用。它给了我:
TypeError: 'set' object is not callable
最佳答案
您的代码确实工作(使用 cpython 2.4、2.5、2.6、2.7、3.1 和 3.2 测试):
>>> a = set(["Blah", "Hello"])
>>> a = list(a) # You probably wrote a = list(a()) here or list = set() above
>>> a
['Blah', 'Hello']
检查您是否没有意外覆盖 list
:
>>> assert list == __builtins__.list
关于Python 设置为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6828722/