>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process  --myjinxin2015 said

# Description:
 
 John learns to play poker with his uncle. His uncle told him: Poker to be in accordance with the order of "2 3 4 5 6 7 8 9 10 J Q K A". The same suit should be put together. But his uncle did not tell him the order of the four suits. 
 
 Give you John's cards and Uncle's cards(two string `john` and `uncle`). Please reference to the order of Uncle's cards, sorting John's cards. 
 
 
# Examples

```
For Python:

Suits are defined as S, D, H, C.

sort_poker("D6H2S3D5SJCQSKC7D2C5H5H10SA","S2S3S5HJHQHKC8C9C10D4D5D6D7")
should return "S3SJSKSAH2H5H10C5C7CQD2D5D6"
sort_poke("D6H2S3D5SJCQSKC7D2C5H5H10SA","C8C9C10D4D5D6D7S2S3S5HJHQHK") 
should return "C5C7CQD2D5D6S3SJSKSAH2H5H10" 

```

Difficulty: EASY
Tags: Sorting

Ad-hoc
Skill types: Sorting

Starter code:
def sort_poker(john, uncle):
	

Solutions:
import re
from collections import OrderedDict
scale = '2 3 4 5 6 7 8 9 10 J Q K A'.split(' ')

def sort_poker(john, uncle):
	order = list(OrderedDict.fromkeys(re.findall('([SDHC])[0-9JQKA]+', uncle)))
	john = re.findall('([SDHC])([0-9JQKA]+)', john)
	return ''.join((''.join(i) for i in sorted(john, key=lambda x: (order.index(x[0]), scale.index(x[1])))))


import re

def sort_poker(H, U, OD='2 3 4 5 6 7 8 9 10 J Q K A'.split()):
	ORDER = re.findall('(.)\\1*', re.sub('[\\dJQKA]', '', U))
	return ''.join(sorted(re.findall('[SDHC](?:[23456789JQKA]|10)', H), key=lambda x: (ORDER.index(x[0]), OD.index(x[1:]))))


order = lambda arr: {card[0]: i for (i, card) in enumerate(arr)}
ranks = order('2 3 4 5 6 7 8 9 10 J Q K A'.split())
suit_table = {ord(suit): ' ' + suit for suit in 'SDHC'}
split_hand = lambda hand: hand.translate(suit_table).split()

def sort_poker(john, uncle):
	suits = order(split_hand(uncle))
	return ''.join(sorted(split_hand(john), key=lambda card: (suits[card[0]], ranks[card[1]])))


def sort_poker(john, uncle):
	card_order = '23456789TJQKA'
	suit_order = [('S', uncle.index('S')), ('D', uncle.index('D')), ('H', uncle.index('H')), ('C', uncle.index('C'))]
	suit_order = [X[0] for X in sorted(suit_order, key=lambda x: x[1])]
	john = john.replace('10', 'T')
	john = [john[i:i + 2] for i in range(0, len(john), 2)]
	john = sorted(john, key=lambda x: (suit_order.index(x[0]), card_order.index(x[1])))
	return ''.join(john).replace('T', '10')


S = lambda h, t={ord(s): ' ' + s for s in 'SDHC'}: h.translate(t).split()
sort_poker = lambda a, b: (lambda s, r: ''.join(sorted(S(a), key=lambda c: (s[c[0]], r[c[1]]))))(*[{c[0]: i for (i, c) in enumerate(S(p))} for p in (b, '2 3 4 5 6 7 8 9 10 J Q K A')])


def sort_poker(john, uncle):
	res = []
	index = 0
	while True:
		try:
			temp = john[index] + john[index + 1]
			if john[index + 1] == '1':
				temp += john[index + 2]
				index += 3
			else:
				index += 2
			res.append(temp)
			temp = ''
		except:
			break
	dict = {}
	for i in 'SDHC':
		dict[i] = uncle.index(i)
	rec = '2 3 4 5 6 7 8 9 10 J Q K A'
	dict2 = {}
	for (i, j) in enumerate(rec.split()):
		dict2[j] = i
	for (i, j) in enumerate(res):
		res[i] = list(j)
		if len(res[i]) == 3:
			res[i][1] = res[i][1] + res[i][2]
			res[i].pop()
	for i in range(len(res)):
		for j in range(i + 1, len(res)):
			if dict2[res[j][1]] < dict2[res[i][1]]:
				temp = res[i]
				res[i] = res[j]
				res[j] = temp
	final = sorted(res, key=lambda x: dict[x[0][0]])
	return ''.join(sum(final, []))


import re

def sort_poker(john, uncle):
	SUITS = re.compile('[SHCD]')
	order = list(dict.fromkeys(SUITS.findall(uncle)))
	ord = {x: order.index(x) for x in order}
	john = re.findall('([CDHS])(\\d+|[JKQA])', john)
	suit = {'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, 'J': 11, 'K': 13, 'Q': 12, 'A': 14}
	a = [(ord[x[0]], suit[x[1]], str(x)) for x in john]
	a.sort(key=lambda x: x[1])
	a.sort(key=lambda x: x[0])
	return ''.join([x for x in ''.join([x[2] for x in a]) if x.isalpha() or x.isnumeric()])


def sort_poker(john, uncle):
	suits = ('S', 'D', 'H', 'C')
	values = ('2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A')
	get_value = lambda index, hand: hand[index + 1:index + 3] if hand[index + 1] == '1' else hand[index + 1]
	get_all_indexes = lambda suit, hand: [i for i in range(len(hand)) if hand.startswith(suit, i)]
	get_cards = lambda hand: {suit: [get_value(index, hand) for index in get_all_indexes(suit, hand)] for suit in suits}
	get_suit_rating = lambda hand: list(dict.fromkeys((symbol for symbol in hand if symbol in suits)))
	johns_hand = sorted([(suit, sorted([card for card in value], key=lambda x: values.index(x))) for (suit, value) in list(get_cards(john).items())], key=lambda x: get_suit_rating(uncle).index(x[0]))
	return ''.join((''.join((suit[0] + value for value in suit[1])) for suit in johns_hand))


import re

def sort_poker(john, uncle):
	(j, s) = (re.findall('([SDHC])([0-9A-Z]0?)', john), ''.join(re.findall('[SDHC]', uncle)))
	n = '2 3 4 5 6 7 8 9 10 J Q K A'
	return ''.join(map(''.join, sorted(j, key=lambda c: (s.find(c[0]), n.find(c[1])))))