Sep-03-2021, 12:38 AM
The problem in your first program is that your card values are strings and they don't sort the way you expect.
One other thing to think about. Do your straights/suites allow the ace to play both high and low? Is [1, 10, 11, 12, 13] a valid straight?
>>> playerhand = [['7', 'h'], ['5', 'h'], ['13', 'H'], ['10', 'h'], ['12', 'h'], ['11', 'h'], ['9', 'h']] >>> sorted(playerhand) [['10', 'h'], ['11', 'h'], ['12', 'h'], ['13', 'H'], ['5', 'h'], ['7', 'h'], ['9', 'h']]If the card values were ints, then the sort would be as expected.
>>> playerhand = [[int(r), s] for r,s in playerhand] >>> sorted(playerhand) [[5, 'h'], [7, 'h'], [9, 'h'], [10, 'h'], [11, 'h'], [12, 'h'], [13, 'H']]That's better.
One other thing to think about. Do your straights/suites allow the ace to play both high and low? Is [1, 10, 11, 12, 13] a valid straight?