python - 列表中的最新文件

时间:2015-03-28 02:31:17

标签: python

我有一个这样的列表 -

list = [['multinational_intel_2014-10-22T110406Z.zip', '2014 10 22 11:05:19'],
        ['multinational_intel_2014-10-24T140006Z.zip', '2014 10 24 14:02:51'],
        ['multinational_intel_2014-11-12T104622Z.zip', '2014 11 12 10:47:49'],
        ['multinational_intel_2014-11-10T131155Z.zip', '2014 11 10 13:13:57'],
        ['multinational_intel_2014-11-14T172344Z.zip', '2014 11 14 17:25:17'],
        ['multinational_intel_2014-11-11T103518Z.zip', '2014 11 11 10:36:47']]

我想扫描列表并获取与最近日期相关联的文件。

对于list我的预期输出是 -

multinational_intel_2014-11-14T172344Z.zip

1 个答案:

答案 0 :(得分:2)

一种方法是使用sorted

list = [['multinational_intel_2014-10-22T110406Z.zip', '2014 10 22 11:05:19'],
        ['multinational_intel_2014-10-24T140006Z.zip', '2014 10 24 14:02:51'],
        ['multinational_intel_2014-11-12T104622Z.zip', '2014 11 12 10:47:49'],
        ['multinational_intel_2014-11-10T131155Z.zip', '2014 11 10 13:13:57'],
        ['multinational_intel_2014-11-14T172344Z.zip', '2014 11 14 17:25:17'],
        ['multinational_intel_2014-11-11T103518Z.zip', '2014 11 11 10:36:47']]

sorted_list = sorted(list, key=lambda x: x[1], reverse=True)
most_recent = sorted_list[0][0]
print most_recent