gpt4 book ai didi

python - 类型错误 : 'set' object does not support indexing

转载 作者:太空狗 更新时间:2023-10-29 20:55:30 25 4
gpt4 key购买 nike

我刚刚在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com