Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignore characters during .sort python

Tags:

python

I need some help on sorting 2 lists..one with file listings and one with directory listings. These lists are generated through another part in a much larger script that I cannot put on here.

filelist = ['EN088_EFH_030_comp_v011.mov', 'EN086_EHA_010_comp_v031.mov', 'EN083_WDA_400_comp_v021.mov', 'EN086_EHA_020_comp_v010.mov', 'EN083_WDA_450_comp_v012.mov']

folderlist = ['[EN086_EHA_010_comp_v031]', '[EN083_WDA_400_comp_v021]', '[EN086_EHA_020_comp_v010]', '[EN083_WDA_450_comp_v012]']

using .sort I can get the data to output like this.

[CB083_WDA_400_comp_v021]
[CB083_WDA_450_comp_v012]
[CB086_EHA_010_comp_v031]
[CB086_EHA_020_comp_v010]
CB083_WDA_400_comp_v021.mov
CB083_WDA_450_comp_v012.mov
CB086_EHA_010_comp_v031.mov
CB086_EHA_020_comp_v010.mov
CB088_EFH_030_comp_v011.mov

But I need it to output like this

[CB083_WDA_400_comp_v021]
CB083_WDA_400_comp_v021.mov
[CB083_WDA_450_comp_v012]
CB083_WDA_450_comp_v012.mov
[CB086_EHA_010_comp_v031]
CB086_EHA_010_comp_v031.mov
[CB086_EHA_020_comp_v010]
CB086_EHA_020_comp_v010.mov
CB088_EFH_030_comp_v011.mov

How can I go about sorting it but ignoring the [] during the sort?
Or what would I do to get the second output?
I'm kind of stumped on what I should do.
Any tips or suggestions?

like image 884
user1995322 Avatar asked Jan 20 '13 20:01

user1995322


1 Answers

....sort(key=lambda x: x.strip('[]'))
like image 187
Ignacio Vazquez-Abrams Avatar answered Oct 08 '22 06:10

Ignacio Vazquez-Abrams