【发布时间】:2018-06-13 07:17:19
【问题描述】:
我是 python 新手。我想从 col2 中找到与列表 col1 中的值 'men'、'women' 和 'people' 相关的最大值。比如,['men', 12, '1946-Truman.txt'], ['women', 7, '1946-Truman.txt']and['people', 49, '1946-Truman.txt'] 包含男性、女性和人的 col2 的最大值。
一种可能的解决方案是将此元组列表转换为男性、女性和人的三个单独数组,然后从所有数组中找到最大值。但是,我想要一个更好的解决方案。
数据:
[['men', 2, '1945-Truman.txt']
['women', 2, '1945-Truman.txt']
['people', 10, '1945-Truman.txt']
['men', 12, '1946-Truman.txt']
['women', 7, '1946-Truman.txt']
['people', 49, '1946-Truman.txt']
['men', 7, '1947-Truman.txt']
['women', 2, '1947-Truman.txt']
['people', 12, '1947-Truman.txt']
['men', 4, '1948-Truman.txt']
['women', 1, '1948-Truman.txt']
['people', 22, '1948-Truman.txt']
['men', 2, '1949-Truman.txt']
['women', 1, '1949-Truman.txt']
['people', 15, '1949-Truman.txt']
['men', 6, '1950-Truman.txt']
['women', 2, '1950-Truman.txt']
['people', 15, '1950-Truman.txt']
['men', 8, '1951-Truman.txt']
['women', 2, '1951-Truman.txt']
['people', 9, '1951-Truman.txt']
['men', 3, '1953-Eisenhower.txt']
['women', 0, '1953-Eisenhower.txt']
['people', 17, '1953-Eisenhower.txt']]
提前致谢。
【问题讨论】:
标签: python list numpy tuples max