Python Forum

Full Version: why is my list a tuple
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have this code:

hand = []
card = []
flop = []
turn = []
river = []
outs = []
possiblefullhouse = False
cardsdrawn = []


player = Player()

cardsdrawn = []
playersgrade = []

random.shuffle(deck)

hand = ['1', 'C'], ['2', 'C']
flop = ['7', 'S'], ['5', 'S'], ['7', 'D']
turn = ['7', 'H']
river = ['1', 'D']

print(type(turn))
why is my list a tuple?
This code cannot run: Player has not been defined.
This code cannot run because we don't have the function player() and deck has not been assigned.
If I fix both of those the program prints "<class 'list'>".

Please post code that demonstrates the problem you are having.
yeah sorry, but i think my python IDE is playing tricks on me. I would delete the post but i can't sorry
FWIW, in the code you posted, both hand and flop end up as tuples, on lines 18 and 19, respectively.
Good catch ndc85430. They become tuples because Python packs sequences into a tuple:
x = 1, 2, 3, 4, 5  # A sequence
print(type(x), x)  # Becomes a tuple
Output:
<class 'tuple'> (1, 2, 3, 4, 5)
If it is important that things are collected in a list, make sure you make the list.
x = [1, 2, 3, 4, 5]
Not that there's anything wrong with a tuple, mind. It's still a sequence.
thank you very much. I thought i was going crazy here