Python 2.7 Python-如何更改列表列表中的列表顺序

Python 2.7 Python-如何更改列表列表中的列表顺序,python-2.7,Python 2.7,我有一个列表,我想按照一个人离职的时间来排列。我已经做了一个代码,只给我时间,但我需要一些东西来检查时间,并把他们的顺序 inFile=removeHeader(file_name) # the information is taken from a txt file and this only gives me the part of the services #print inFile gives me list of lists like [['Peter', ' 06-CB-89', '

我有一个列表,我想按照一个人离职的时间来排列。我已经做了一个代码,只给我时间,但我需要一些东西来检查时间,并把他们的顺序

inFile=removeHeader(file_name) # the information is taken from a txt file and this only gives me the part of the services
#print inFile gives me list of lists like [['Peter', ' 06-CB-89', ' Xavier', ' 09:45', ' 10:15', ' downtown', ' 10', ' standby'], ['Robert', ' 13-KI-54', ' Paul', ' 09:30', ' 10:30', ' Castle', ' 45', ' standby']

for time in inFile:
    hours=time[4]

    print hours  #this gives me only the hours they left work

您必须按离开时间(即子列表的第5个值)对主列表进行排序,sorted ALO的键参数允许您指定一个函数,该函数将被调用以计算列表排序所依据的键:

import time
x =[['Peter', ' 06-CB-89', ' Xavier', ' 09:45', ' 10:15', ' downtown', ' 10', ' standby'], ['Robert', ' 13-KI-54', ' Paul', ' 09:30', ' 10:30', ' Castle', ' 45', ' standby']]
sorted(x, key = lambda x: x[4])

请考虑编辑您的帖子,以添加更多的解释您的代码做什么,为什么它会解决这个问题。一个只包含代码的答案(即使它在工作)通常不会帮助OP理解他们的问题。