I am using a two dimensional array(a deck) and I am trying to random.sample to fill another list with 5 random items. Though, i get a 3 dimensional list and I cannot fix it
Any help?
import random
suits =['H', 'D', 'S', 'C']
numbers = []
deck = []
for i in range(0, 13):
numbers.append(i+2)
for i in range(len(suits)):
for j in range(len(numbers)):
deck.append([numbers[j], suits[i]])
player1 = []
pc = []
for i in range(5):
player1.append(random.sample(deck, 1))
pc.append(random.sample(deck, 1))
print(player1,pc)
Output:[[[14, 'C']], [[11, 'D']], [[6, 'C']], [[14, 'S']], [[13, 'H']]] [[[2, 'C']], [[6, 'D']], [[11, 'C']], [[6, 'D']], [[9, 'S']]]... I Just cannot get rid of the extra list that's created(I need to use .sample and not .choice which worked fine before)
Thanks in advance,
Aucun commentaire:
Enregistrer un commentaire