[Solved] I am attempting to sort a single hand of cards by rank and suit with no builtins in Python 3 using the code I have [closed]


If I am following your code correctly, the variables card1 and card2 should contain some string like 'AC' or '5D'. It looks like you want to look at the suit and the number separately (value.find(card1[0] [0]) + ((suit.find(card1[0][1]))*20)). You only need one index here, not two. Check out the below example:

>>> a="AC"
>>> a[0]
'A'
>>> a[1]
'C'
>>> a[0][0]
'A'
>>> a[0][1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: string index out of range

The string 'C' has only one element, so when you do card1[0][1] you get an index error. You want to replace that code with

card1 = value.find(card1[0]) + ((suit.find(card1[1]))*20)
card2 = value.find(card2[0]) + ((suit.find(card2[1]))*20)

That should get rid of your IndexError.

1

solved I am attempting to sort a single hand of cards by rank and suit with no builtins in Python 3 using the code I have [closed]