小编Luc*_*ian的帖子

从列表中按键生成字典列表

我有一个清单:

['8C', '2C', 'QC', '5C', '7C', '3C', '6D', 'TD', 'TH', 'AS', 
 'QS', 'TS', 'JS', 'KS']
Run Code Online (Sandbox Code Playgroud)

我需要得到这样的字典:(排序并不重要)

{'C': ['QC', '8C', '7C', '5C', '3C', '2C'], 
 'S': ['AS', 'KS', 'QS', 'JS', 'TS']
}
Run Code Online (Sandbox Code Playgroud)

码:

def parse_flush(cards):
    cards = sort_by_color(cards)
    flush_dic = {}
    print str(cards)
    count = 0
    pos = 0
    last_index = 0
    for color in colors:
        for i, card in enumerate(cards):
            if card[1] == color:
                count += 1
                last_index = i+1
                if count == 1:
                    pos = i
        if count >= 5: …
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
1
解决办法
91
查看次数

标签 统计

python ×1