python - Sorting files based on the number in them -
i having few files like..
l.1,l.3,l.2,l.12,l.36,l.24
when sorting list giving me...
l.1,l.12,l.2,l.24,l.3,l.36
how can them in way?..
l.2,l.2,l.3,l.12,l.24,l.36
note: because not permitting add actual file name ve given list. actual file names joined '.' l.1 l.2
i can write bubble sort algorithm that. want simpler way..
thanks
here go:
l = ['l.1','l.3','l.2','l.12','l.36','l.24'] sorted(l, key = lambda x: int(x[2:]))
Comments
Post a Comment