我想编写一个程序,以随机顺序显示列表的所有元素而不重复.在我看来它应该工作,但只打印那些重复的元素.
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
Run Code Online (Sandbox Code Playgroud)