Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why is my list a tuple
#1
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?
Reply
#2
This code cannot run: Player has not been defined.
Reply
#3
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.
Reply
#4
yeah sorry, but i think my python IDE is playing tricks on me. I would delete the post but i can't sorry
Reply
#5
FWIW, in the code you posted, both hand and flop end up as tuples, on lines 18 and 19, respectively.
buran and deanhystad like this post
Reply
#6
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]
Reply
#7
Not that there's anything wrong with a tuple, mind. It's still a sequence.
Reply
#8
thank you very much. I thought i was going crazy here
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  using > < for tuple , list,... akbarza 3 487 Feb-05-2024, 01:18 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 493 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Change font in a list or tuple apffal 4 2,700 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  search a list or tuple for a specific type ot class Skaperen 8 1,949 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  in a list or tuple Skaperen 6 92,907 May-16-2021, 09:59 PM
Last Post: Skaperen
  Create SQLite columns from a list or tuple? snakes 6 8,736 May-04-2021, 12:06 PM
Last Post: snakes
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 4,400 Jan-30-2021, 07:11 AM
Last Post: alloydog
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,847 Nov-04-2020, 11:26 AM
Last Post: Aggam
  Python Error- TypeError: ('Params must be in a list, tuple, or Row', 'HY000') DarkCoder2020 3 5,607 Jul-29-2020, 12:02 AM
Last Post: Larz60+
  Arrange list of tuple using loop batchenr 7 3,495 Jun-16-2019, 03:24 PM
Last Post: Abdullah

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020