I'm using python to write a programme for poker following a course on Udacity. One of the definitions i'm using is the following which i'm using from the course.
def card_ranks(cards):
"Return a list of the ranks, sorted with higher first."
ranks = ['--23456789TJQKA'.index(r) for r,s in cards]
ranks.sort(reverse=True)
return ranks
So this is meant to for example cards_ranks([TH,9C,9D,7S]) should return [10,9,9,7]. However i'm getting the following error
ValueError Traceback (most recent call
last)
<ipython-input-13-ff8fb242bb41> in <module>()
----> 1 card_ranks(['9H','8C','7C','10D'])
<ipython-input-12-7eaf1ab781bc> in card_ranks(cards)
1 def card_ranks(cards):
2 "Return a list of the ranks, sorted with higher first."
----> 3 ranks = ['--23456789TJQKA'.index(r) for r,s in cards]
4 ranks.sort(reverse=True)
5 return ranks
ValueError: too many values to unpack
Does anyone know how to fix it? Btw i'm new to list comprehension i did try the following myself which works if only numbers in the cards are used
def card_ranks(cards):
"Return a list of the ranks, sorted with higher first."
ranks = [r[0] for r in cards]
ranks.sort(reverse=True)
return ranks
So naturally i tried
def card_ranks(cards):
"Return a list of the ranks, sorted with higher first."
ranks = ['--23456789TJQKA'.index(r[0]) for r in cards]
ranks.sort(reverse=True)
return ranks
But that also did not work. I would really appreciate any help, the code is meant to work but it does not when i'm using it. I'm using a Jupyter notebook.