Skip to content
Advertisement

How to custom sort a string list of deck of cards?

I am making a card game in python, consisting of 3 bots and a player. The deck of 52 cards is randomly distributed and stored in 4 separate lists of 13 cards each.

JavaScript

Here, H5 stands for 5 of hearts, DJ as Joker of Diamonds, SA as Ace of Spades and so on. But, I want to sort these lists of strings in order of the value of cards i.e. A > K > Q >J > 10 > 9 > 8 > 7 > 6 > 5 > 4 > 3 > 2 For eg., after sorting the bot1 list will look like

JavaScript

Is is possible to sort in this manner? If yes, then how?

Advertisement

Answer

You may get the values ordered in a string for example, then use the index in that list to order the card set

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement