Skip to content Skip to sidebar Skip to footer

Python Sort List Using Lambda Function

I have a list like this: [ 'C:\\Users\\Rash\\Downloads\\Programs\\a.txt', 'C:\\Users\\Rash\\Downloads\\a.txt', 'C:\\Users\\Rash\\a.txt', 'C:\\Users\\ab.txt', 'C

Solution 1:

Return a sequence from the key function that contains the items you want to sort by.

key=lambda x: (x.count('\\'), x.split('\\'))

Post a Comment for "Python Sort List Using Lambda Function"