for example if i had a text file which contains:
[1,2,3,4,5]
[1,2,3]
[1,2,3,4]
to:
[1,2,3]
[1,2,3,4]
[1,2,3,4,5]
data = [[1, 2, 3, 4, 5], [6, 7, 8], [3, 5, 8, 2]]
sorted(data, key=lambda x : len(x))
Result with:
[[6, 7, 8], [3, 5, 8, 2], [1, 2, 3, 4, 5]]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.