【python/shell】list.sort()与ls | find 排序差异分析

Date: 2018.10.11


1、参考

https://www.cnblogs.com/monsteryang/p/6938779.html
https://blog.csdn.net/inrgihc/article/details/49851639

2、python中列表sort函数与shell中sort命令

python中列表sort函数:

list = []
list.sort()
list.sort(key=str.lower)

sort():未指定任何参数时,是按照字典序(ASCII码顺序)从小到大进行排序的;可以指定key=str.lower,按照小写字母从小到大进行排序。

shell中sort命令:

cat test.txt
sort test.txt

shell中的sort命令用于对文本文件中的行按照字典序(ASCII码顺序)从小到大进行排序。

3、通过shell中的ls命令排序
list=${find ./dir -name ".txt"}
ls ${list}

find没有确定的排序规则,通过ls排序后,列表是按照字典序(ASCII码顺序)从小到大进行排序的。


THE END!

原文地址:https://www.cnblogs.com/SoaringLee/p/10532344.html