如何在IronPython中对FileInfo列表进行排序 [英] how to sort list of FileInfo in IronPython
本文介绍了如何在IronPython中对FileInfo列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出FileInfo对象的列表,如何按日期对它们进行排序?具体来说,我想按CreationTime对它们进行降序排序.
Given a list of FileInfo objects, how do I sort them by date? Specifically I want to sort them by CreationTime in descending order.
推荐答案
Pythonic的实现方式是:
The Pythonic way of doing this would be:
fileInfos = list(DirectoryInfo(path).GetFiles())
fileInfos.sort(key=lambda f: f.CreationTime, reverse=True)
列表排序方法具有一个键函数,该函数用于获取每个项目的排序键.
The list sort method takes a key function that is used to get the sort key for each item.
这篇关于如何在IronPython中对FileInfo列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文