Python 从列表中删除项目并更新它

Python 从列表中删除项目并更新它,python,list,Python,List,我有一个游戏,玩家从列表中选择挑战: locallist = ['Ann-Marie, the butcher (1)', 'Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)'] 每次挑战后,我都会重新打印列表,以便他们可以选择另一个挑战,我希望它打印一个列表,不包括他们刚刚进行的人员挑战 感谢您提供从原始列表创建集合的任何见解

我有一个游戏,玩家从列表中选择挑战:

locallist = ['Ann-Marie, the butcher (1)', 'Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
每次挑战后,我都会重新打印列表,以便他们可以选择另一个挑战,我希望它打印一个列表,不包括他们刚刚进行的人员挑战


感谢您提供从原始列表创建集合的任何见解。然后从集合中删除拾取的项目并打印集合。

您可以从原始列表中创建集合。然后从集合中删除拾取的项目并打印集合。

您可以从原始列表中创建集合。然后从集合中删除拾取的项目并打印集合。

您可以从原始列表中创建集合。然后从集合和打印集合中删除拾取的项目。

根据用户选择的方式,您可以使用“删除”或“弹出”:

locallist = ['Ann-Marie, the butcher (1)', 'Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']

pick = 'Ann-Marie, the butcher (1)'
locallist.remove('Ann-Marie, the butcher (1)')
print(locallist)

pick = 1
locallist.pop(1)
print(locallist)

['Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
['Bella, the flourist (2)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
如果要保持原始列表的完整性,请复制
locallist

remaining = locallist[:]
pick = 'Ann-Marie, the butcher (1)'
remaining.remove('Ann-Marie, the butcher (1)')
print(remaining)

pick = 1
remaining.pop(1)
print(remaining )

['Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
['Bella, the flourist (2)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
使用
pop
还将为您提供值,以便您可以在需要时使用:

pick = 1
challenge = remaining.pop(1)
print("You chose the following challenge: {}".format(challenge))
You chose the following challenge: Bella, the flourist (2)

根据用户选择的方式,可以使用“删除”或“弹出”:

locallist = ['Ann-Marie, the butcher (1)', 'Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']

pick = 'Ann-Marie, the butcher (1)'
locallist.remove('Ann-Marie, the butcher (1)')
print(locallist)

pick = 1
locallist.pop(1)
print(locallist)

['Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
['Bella, the flourist (2)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
如果要保持原始列表的完整性,请复制
locallist

remaining = locallist[:]
pick = 'Ann-Marie, the butcher (1)'
remaining.remove('Ann-Marie, the butcher (1)')
print(remaining)

pick = 1
remaining.pop(1)
print(remaining )

['Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
['Bella, the flourist (2)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
使用
pop
还将为您提供值,以便您可以在需要时使用:

pick = 1
challenge = remaining.pop(1)
print("You chose the following challenge: {}".format(challenge))
You chose the following challenge: Bella, the flourist (2)

根据用户选择的方式,可以使用“删除”或“弹出”:

locallist = ['Ann-Marie, the butcher (1)', 'Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']

pick = 'Ann-Marie, the butcher (1)'
locallist.remove('Ann-Marie, the butcher (1)')
print(locallist)

pick = 1
locallist.pop(1)
print(locallist)

['Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
['Bella, the flourist (2)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
如果要保持原始列表的完整性,请复制
locallist

remaining = locallist[:]
pick = 'Ann-Marie, the butcher (1)'
remaining.remove('Ann-Marie, the butcher (1)')
print(remaining)

pick = 1
remaining.pop(1)
print(remaining )

['Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
['Bella, the flourist (2)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
使用
pop
还将为您提供值,以便您可以在需要时使用:

pick = 1
challenge = remaining.pop(1)
print("You chose the following challenge: {}".format(challenge))
You chose the following challenge: Bella, the flourist (2)

根据用户选择的方式,可以使用“删除”或“弹出”:

locallist = ['Ann-Marie, the butcher (1)', 'Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']

pick = 'Ann-Marie, the butcher (1)'
locallist.remove('Ann-Marie, the butcher (1)')
print(locallist)

pick = 1
locallist.pop(1)
print(locallist)

['Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
['Bella, the flourist (2)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
如果要保持原始列表的完整性,请复制
locallist

remaining = locallist[:]
pick = 'Ann-Marie, the butcher (1)'
remaining.remove('Ann-Marie, the butcher (1)')
print(remaining)

pick = 1
remaining.pop(1)
print(remaining )

['Bella, the flourist (2)', 'Caitlyn, the painter(3)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
['Bella, the flourist (2)', 'Daniel, the scientist (4)', 'Lauren, the Zookeeper (5)']
使用
pop
还将为您提供值,以便您可以在需要时使用:

pick = 1
challenge = remaining.pop(1)
print("You chose the following challenge: {}".format(challenge))
You chose the following challenge: Bella, the flourist (2)


用户输入什么??整数??是要从列表中删除某个项目,还是要保持列表不变,但打印时不使用指定的元素?用户输入是整数用户输入的是什么??整数??是要从列表中删除某个项目,还是要保持列表不变,但打印时不使用指定的元素?用户输入是整数用户输入的是什么??整数??是要从列表中删除某个项目,还是要保持列表不变,但打印时不使用指定的元素?用户输入是整数用户输入的是什么??整数??是要从列表中删除某个项目,还是保持列表不变,但打印时保留指定的元素?用户输入无效integers@Hackaholic,这两方面我都讲过了scenarios@hennessyd不worries@Hackaholic,这两方面我都讲过了scenarios@hennessyd不worries@Hackaholic,这两方面我都讲过了scenarios@hennessyd,不worries@Hackaholic,这两方面我都讲过了scenarios@hennessyd,不用担心