小编Sak*_*hen的帖子

TypeError:'set'对象不支持索引

我刚刚在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])
Run Code Online (Sandbox Code Playgroud)

但令人满意的随机成功的感觉并没有超过我.相反,失败的感觉:

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
Run Code Online (Sandbox Code Playgroud)

请帮忙

python set python-3.x

8
推荐指数
2
解决办法
4万
查看次数

标签 统计

python ×1

python-3.x ×1

set ×1