我刚刚在 Python 3.5 中做了一些随机的事情。 在 15 分钟的空闲时间里,我想到了这个:
a = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
"x", "y", "z"}
len_a = len(a)
list = list(range(0, len_a))
message = ""
wordlist = [ch for ch in message]
len_wl = len(wordlist)
for x in list:
print (a[x])
但那种随机成功的满足感并没有让我失望。 相反,失败的感觉确实:
Traceback (most recent call last):
File "/Users/spathen/PycharmProjects/soapy/soup.py", line 9, in <module>
print (a[x])
TypeError: 'set' object does not support indexing
请帮忙
最佳答案
试试方括号:
a = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
"x", "y", "z"]
即:使用 list
而不是 set
关于python - 类型错误 : 'set' object does not support indexing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43991057/