# Check if player has a flush or not fails

Check if player has a flush or not fails
0
#1

Hello,

I am coding a teminal based poker “simulator” and I am trying to check if any of the users has a flush or not.

I have a if/else where I test the best hand first and the worst hand last so it passes down if return is false.

this is the flush function.

[‘5s’, ‘8s’, ‘9s’, ‘As’, ‘2s’] gives true
[‘5s’, ‘2h’, ‘8s’, ‘9s’, ‘As’, ‘2s’] gives false

``````def is_flush(h):
suits = [x[-1] for x in h]
if len(set(suits)) == 1:
return True, h
else:
return False
``````

The function is correct isnt it? I dont understand why it doesnt work when a card with another suit is added to the hand? It doesnt make sense

#2

For the example `['5s', '2h', '8s', '9s', 'As', '2s']`, `set(suits)` would return `{'h', 's'}`, so the length would be `2` which would not be equal to `1`.

1 Like
#3

It does however give me 6 and not 2 -

``````[‘s’, ‘h’, ‘s’, ‘s’, ‘s’, ‘s’]

``````

Can you please give me one more clue so i can solve it? I surely need to loop thru the Suits and compare all the items and count how many There is of each suit

#4

What code gives you 6?

#5

You already have a list of `suits`, so you could start with an empty dictionary (call it `counts`) and iterate through the `suits` list and assign the count of each suit as a value for a `suit` key in the counts dictionary. Then, you can use the `any` function to return True or False based on finding any suite with a count >= 5 in the `counts` dictionary.

#6

Thank you. I should have figured. Very easy