I have the following list:
my_list = ['name.13','name.1', 'name.2','name.4', 'name.32']
And I would like sort the list and print it out in order, like this
name.1
name.2
name.4
name.13
name.32
What I have tried so far is:
print sorted(my_list)
name.1
name.13
name.2
name.32
name.4
The sorted() command obviously treats the string alphabetically. Maybe it would be better to sort numerically after detecting the .
first?
Is there an good way to sort it properly? What would be the most efficient approach to take? How would I apply this is I had a list of tuples and wanted to sort it using the second elemnt of the tuples? For instance:
tuple_list = [('i','name.2'),('t','name.13'),('s','name.32'),('l','name.1'),('s','name.4')]
print tuple_list
'l','name.1'
'i','name.2'
's','name.4'
't','name.13'
's','name.32'
Thanks for your help and, as always, comment if you think the question can be improved/clarified.
Alex