Sorting a mix of letters and numbers in Python

preview_player
Показать описание
It's easy to sort numbers in Python, and even to sort strings -- but what if you have a mix of the two? This question came up in corporate training that I did yesterday, and I decided to review the answer here, using a combination of strings, lists, tuples, and list comprehensions.

Рекомендации по теме
Комментарии
Автор

Great little exercise. I was able to do it in two lines (excluding the first line).

my_list = ['a2', 'b3', 'c4', 'a5', 'b12', 'c1', 'a11', 'b10', 'c14']
seperated = [(item[0], int(item[1:])) for item in my_list]
sorted(seperated)

mansouralshamri