Python-Poker自定义范围列表,输出结构问题

Python-Poker自定义范围列表,输出结构问题,python,list,nonetype,poker,Python,List,Nonetype,Poker,这代表了所有6种使AA和所有32只牌的K值高,J值至少为第二高的牌。我不知道这是否是最好的方法,但它回答了你的问题 将函数重写为,如下所示: [[('Ad', 'Ac'), ('Ad', 'Ah'), ('Ad', 'As'), ('Ac', 'Ah'), ('Ac', 'As'), ('Ah', 'As')], [[('Td', 'Kd'), ('Td', 'Kc'), ('Td', 'Kh'), ('Td', 'Ks'), ('Tc', 'Kd'), ('Tc', 'Kc'), ('Tc',

这代表了所有6种使AA和所有32只牌的K值高,J值至少为第二高的牌。

我不知道这是否是最好的方法,但它回答了你的问题

将函数重写为,如下所示:

[[('Ad', 'Ac'), ('Ad', 'Ah'), ('Ad', 'As'), ('Ac', 'Ah'), ('Ac', 'As'), ('Ah', 'As')], [[('Td', 'Kd'), ('Td', 'Kc'), ('Td', 'Kh'), ('Td', 'Ks'), ('Tc', 'Kd'), ('Tc', 'Kc'), ('Tc', 'Kh'), ('Tc', 'Ks'), ('Th', 'Kd'), ('Th', 'Kc'), ('Th', 'Kh'), ('Th', 'Ks'), ('Ts', 'Kd'), ('Ts', 'Kc'), ('Ts', 'Kh'), ('Ts', 'Ks')], [('Jd', 'Kd'), ('Jd', 'Kc'), ('Jd', 'Kh'), ('Jd', 'Ks'), ('Jc', 'Kd'), ('Jc', 'Kc'), ('Jc', 'Kh'), ('Jc', 'Ks'), ('Jh', 'Kd'), ('Jh', 'Kc'), ('Jh', 'Kh'), ('Jh', 'Ks'), ('Js', 'Kd'), ('Js', 'Kc'), ('Js', 'Kh'), ('Js', 'Ks')], [('Qd', 'Kd'), ('Qd', 'Kc'), ('Qd', 'Kh'), ('Qd', 'Ks'), ('Qc', 'Kd'), ('Qc', 'Kc'), ('Qc', 'Kh'), ('Qc', 'Ks'), ('Qh', 'Kd'), ('Qh', 'Kc'), ('Qh', 'Kh'), ('Qh', 'Ks'), ('Qs', 'Kd'), ('Qs', 'Kc'), ('Qs', 'Kh'), ('Qs', 'Ks')]]]
现在,当您调用
printmakerange(['AA','KJ+')
时,输出是一个长度为38的列表:

def makerange(hands, group = allholdemhands):
    'create a range of all hands from list of types'
    handrange = []
    for hand in hands:
        if hand[-1] != '+':
            for hand in allcombos(hand,group):
                handrange.append(hand)
        else:
            for hand in allbettercombos(hand,group):
                handrange.append(hand)
    return handrange

更多信息。现在,也许代码可以重构,但它应该按照您的意愿工作。

那么您是说您会像
makerange(['AA',KJ+'))那样调用函数。
?是的,这正是正确的次要观点,但奇怪的是,在
deck
之后定义
ranks='23456789TJQKA'
,即使
ranks
的值用于定义
deck
@mariomendoza,也不客气!如果它解决了你的问题,请接受它作为答案!来自:“请不要对您的问题或答案添加评论以说‘谢谢’。[…]如果您想说‘谢谢’,请投票或接受此人的答案[…]
def allcombos(hand,group):
    'give all combos of a given hand for a given game'
    for i in group:
        if (i[0][0] == hand[0] and i[1][0] == hand[1]) or (i[0][0] == hand[1] and i[1][0] == hand[0]):
            yield i

def allbettercombos(cards,group):
    'all combos as good as or better, of that type'
    if cards[0] == cards[1]:
        betterpairs = [i+i for i in ranks if ranks.index(i) >= ranks.index(cards[0])]
        for x in betterpairs:
            for hand in allcombos(x,group):
                yield hand
    else:
        bettercards = [cards[0]+i for i in ranks if ranks.index(i) >= ranks.index(cards[1]) and ranks.index(i) < ranks.index(cards[0])]
        for x in bettercards:
            for hand in allcombos(x,group):
                yield hand
def makerange(hands, group = allholdemhands):
    'create a range of all hands from list of types'
    handrange = []
    for hand in hands:
        if hand[-1] != '+':
            for hand in allcombos(hand,group):
                handrange.append(hand)
        else:
            for hand in allbettercombos(hand,group):
                handrange.append(hand)
    return handrange
[('Ad', 'Ac'), ('Ad', 'Ah'), ('Ad', 'As'), ('Ac', 'Ah'), ('Ac', 'As'), ('Ah', 'As'), ('Jd', 'Kd'), ('Jd', 'Kc'), ('Jd', 'Kh'), ('Jd', 'Ks'), ('Jc', 'Kd'), ('Jc', 'Kc'), ('Jc', 'Kh'), ('Jc', 'Ks'), ('Jh', 'Kd'), ('Jh', 'Kc'), ('Jh', 'Kh'), ('Jh', 'Ks'), ('Js', 'Kd'), ('Js', 'Kc'), ('Js', 'Kh'), ('Js', 'Ks'), ('Qd', 'Kd'), ('Qd', 'Kc'), ('Qd', 'Kh'), ('Qd', 'Ks'), ('Qc', 'Kd'), ('Qc', 'Kc'), ('Qc', 'Kh'), ('Qc', 'Ks'), ('Qh', 'Kd'), ('Qh', 'Kc'), ('Qh', 'Kh'), ('Qh', 'Ks'), ('Qs', 'Kd'), ('Qs', 'Kc'), ('Qs', 'Kh'), ('Qs', 'Ks')]