teromakotero icon

Shuffle List

teromakotero | PRO | 05/07/19 08:41:18 PM UTC | 0 ⭐ | 331 👁️ | Never ⏰ | []
Python |

910 B

|

None

|

0 👍

/

0 👎

from random import shuffle
 
players = ['Harry', 'Hermione', 'Neville', 'Ginny']
players2 = ['Harry', 'Ginny'] 
players3 = ['Harry']
players4 = []
players5 = ['A', 'B', 'C', 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R']
 
def shuffle_list(team):
    team1 = []
    team2 = []
    shuffle(team)
    if(len(team) == 0):
        print("This is an empty list!")
    for k in range(len(team)):
        if(len(team) > 0):
            team1.append(team.pop())
        if(len(team) > 0):
            team2.append(team.pop())
    print("team1:")
    for i in team1:
        print(i)
    print("")
    print("team2:")
    for j in team2:
        print(j)
    print("")
        
 
print("players")
shuffle_list(players)
print("players2")
shuffle_list(players2)
print("players3")
shuffle_list(players3)
print("players4")
shuffle_list(players4)
print("players5")
shuffle_list(players5)

Comments