Sorting a mix of letters and numbers in Python

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024

Комментарии • 3

  • @mansouralshamri1387
    @mansouralshamri1387 3 месяца назад +1

    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)