从这里获取解决方案:How to sort a list of lists by a specific index of the inner list?
from operator import itemgetter
L=[['University of Michigan','James Jones','phd'],['University of Georgia','Anne Greene','ba'],['University of Michigan','Frank Kimball','ma'],['University of Florida','Nate Franklin','ms'],['University of Georgia','Sara Dean','ms'],['University of Georgia','Beth Johnson','bs']]
print 'Before:', L
print ' After:', sorted(L, key=itemgetter(0))
输出
Before: [['University of Michigan', 'James Jones', 'phd'], ['University of Georgia', 'Anne Greene', 'ba'], ['University of Michigan', 'Frank Kimball', 'ma'], ['University of Florida', 'Nate Franklin', 'ms'], ['University of Georgia', 'Sara Dean', 'ms'], ['University of Georgia', 'Beth Johnson', 'bs']]
After: [['University of Florida', 'Nate Franklin', 'ms'], ['University of Georgia', 'Anne Greene', 'ba'], ['University of Georgia', 'Sara Dean', 'ms'], ['University of Georgia', 'Beth Johnson', 'bs'], ['University of Michigan', 'James Jones', 'phd'], ['University of Michigan', 'Frank Kimball', 'ma']]
+1从u学到很多东西;) – zhangxaochen
@zhangxaochen欢迎您:)你善于numpy的自己:) – thefourtheye
待办事项不要忘记,Python 2.6.6中不存在Counter,因此如果以后的Python不可用,就不能使用它。 – sabbahillel