【发布时间】:2015-06-09 15:04:38
【问题描述】:
我想编写一个程序,以随机顺序显示列表的所有元素而不重复。 在我看来,它应该可以工作,但只会重复打印这些元素。
import random
tab = []
for i in range(1, 8):
item = random.choice(["house", "word", "computer", "table", "cat", "enter", "space"])
if item not in tab:
print(item)
else:
tab.append(item)
continue
【问题讨论】: