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

10-06 13:51
查看更多