0
import random

players = ["abc", "dfg", "igh", "klm", "nip", "qrs"]


#def selction():
random_selection = random.choice(players)
print(random_selection)

for i in players:
    if str(players[i]):
        players.remove(i)
    else:
        print(i)

I am trying to build a quick program to help select players from a list to create a order for a lineup. Once a player is selected, it should be removed from the list so the output is the not the same player over again.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Awadis
  • 7
  • 1
  • Can you explain the results of your code above and what issues you are facing? – Sin Han Jinn Dec 22 '22 at 01:28
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 22 '22 at 01:28
  • So the goal is to randomly generate a name from a list "players". if the name is drawn than that name should not be drawn again. There should be different name from the list "players" until no more names are left. Hope this was more clear. sorry – Awadis Dec 22 '22 at 01:33

1 Answers1

1

Shuffle the list of players and remove them one by one (from the front or back).

from random import shuffle
players = ["abc", "dfg", "igh", "klm", "nip", "qrs"]
shuffle(players)
for player in players:
    print(player)
# remove from the back with players.pop()
Unmitigated
  • 76,500
  • 11
  • 62
  • 80