I would like some help. The goal os this function is to find if there is a pair in a set of cards and find out which are them.
I am able to reach the value with the print command, but my for loop is broken.
def check_pair(cards):
print(cards) #works
print(cards[1][1]) #works
for i in cards:
ranks.append(cards[i][0])
pairs = {k:ranks.count(k) for k in ranks}
return pairs
community_cards = [(1, 'd'), (2, 'h'), (1, 'h')]
print(f'Checking pair: {check_pair(community_cards)}')
File “e:Python_BooksPython Crash Coursepoker.py”, line 42, in check_pair
ranks.append(cards[i][0])
~~~~~^^^
TypeError: list indices must be integers or slices, not tuple
PS E:Python_BooksPython Crash Course>
João Schultz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.