我正在尝试从列表中删除字符串,在选择这些字符串后,我将避免再次获取同一个单词,但当我尝试.remove或.pop时,它不会删除该单词。这是为什么,我怎么能分类?
我还试图创建一个单词的副本,如果它在从函数返回单词之前被删除,如果它已经被选中,这会影响单词吗?
谢谢你的帮助,我是编程新手,你可能会说!
def choose_a_word_easy(): # function for choosing random easy word.
words = ['ant', 'bee', 'cat', 'dog', 'egg', 'hat', 'golf', 'jelly', 'king', 'bird', 'hot', 'cold', 'fish', 'log',
'dad', 'mum', 'goal', 'help', 'file', 'neat', 'car', 'moon', 'eye', 'tree', 'rice', 'ice', 'speed', 'rat',
'water', 'rain', 'snow', 'spoon', 'light', 'gold', 'zoo', 'oil', 'goat', 'yoga', 'judo', 'japan', 'hello']
pick = random.choice(words) # randomly choose any word from the list.
# p1 = pick
words.remove(pick)
return pick