def to_str(card): """from card(int) to str >>> to_str(0) 'S01' >>> to_str(1) 'H01' >>> to_str(4) 'S02' """ num = to_num(card) suit = "CDHS"[card % 4] return "%s%02d" % (suit, num) def to_num(card): return card / 4 + 1 def get_mid(*xs): """ >>> get_mid(1, 5, 2) 2 >>> get_mid(1, 1, 1) 1 """ if len(xs) == 1: xs = xs[0] assert len(xs) == 3 return sorted(xs)[1] def _test(): import doctest doctest.testmod() if __name__ == "__main__": _test()