首页 > 解决方案 > 如何根据字典中的多个列表创建新列表?

问题描述

我正在尝试定义一个函数,该函数将具有多个列表的字典作为值,并为每个索引位置创建一个新列表。我可以使用我当前的功能一次完成一项。但是想要做到这一点,所以所有列表都是通过一个函数调用创建的。谢谢你的帮助 :)

league_standings = {'Brett': [9, 6, 7, 8, 3, 7, 7, 5], 'Matt B': [6, 3, 6, 3, 8, 11, 10, 8],
                    'Will/Derek': [6, 7, 8, 7, 6, 6, 4, 6], 'Bryan': [5, 6, 6, 7, 11, 6, 6, 6],
                    'Sean': [11, 9, 7, 6, 2, 3, 5, 6], 'Joey/Brian': [4, 4, 4, 3, 6, 8, 8, 6],
                    'Tim': [4, 8, 10, 3, 6, 5, 8, 8], 'Adam': [3, 7, 3, 10, 10, 6, 3, 4],
                    'Michael': [7, 9, 6, 8, 6, 9, 10, 5], 'James/Adam': [9, 5, 6, 6, 9, 3, 7, 8],
                    'John': [8, 7, 9, 7, 4, 9, 6, 8], 'Matt R': [6, 7, 6, 10, 10, 5, 4, 8]}

def elim_px(player_dict):
    season = []
    for k,v in player_dict.items():
        season.append(v[0])
    ss = sorted(season)
    bottom_four = ss[:4]
    print(bottom_four)
    stinkers= []
    for k,v in player_dict.items():
        for i in bottom_four:
            if k in stinkers:
                continue
            elif i == v[0]:
                stinkers.append(k)
    print(stinkers)

标签: python-3.xlistfunctiondictionary

解决方案


推荐阅读