python-3.x - 如何根据字典中的多个列表创建新列表?
问题描述
我正在尝试定义一个函数,该函数将具有多个列表的字典作为值,并为每个索引位置创建一个新列表。我可以使用我当前的功能一次完成一项。但是想要做到这一点,所以所有列表都是通过一个函数调用创建的。谢谢你的帮助 :)
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)
解决方案
推荐阅读
- php - Laravel 5.7:更新方法返回“无消息”
- python - ConcatOp:输入的尺寸应匹配:shape[0] = [1,1024,300,476] 与 shape[1] = [1,1024,76,120]
- android - 当我的应用程序处于 onpause 时如何清除 arraylist 并在 onresume 时再次接收
- php - Laravel:如何隐藏重复值
- google-drive-api - Google Drive API v3:如何在文件上设置 canCopy 功能
- python - cowplot::plot_grid 中的错误:未使用的参数(plot.c、plot.def、labels =“AUTO”)和arrangeGrob(...)中的错误:nrow * ncol >= n 不是 TRUE
- r - 错误(函数(优化器 = “bobyqa”,restart_edge = TRUE,boundary.tol = 1e-05)
- video - 视频渐变?
- antd - 如何使用侧边栏从可折叠状态的菜单项中删除默认工具提示?
- node.js - 什么算作 Firestore 中的读取操作?