I have the following list:
list1 = ['# Heading', '200: Stop Engine', '', '20: Start Engine', '400: Do xy']
and I want to get:
list2 = ['20: Start Engine', '200: Stop Engine', '400: Do xy']
So the empty list item and the ones starting with # should be deleted or ignored and the rest should be sorted by the number. I tried to use split() to extract the numbers and the #:
list2 = [i.split() for i in list1]
but then I get a list in a list brings some other problems (I need to convert the content of the list to an int for the sorting which only works if I have a string). The output would be:
list2 = ['#', 'Heading', '200:', 'Stop', 'Engine', '', '20:', 'Start', 'Engine', '400:', 'Do', 'xy']
and if I split(':'), I can't delete the #.
For the sorting I tried:
list2.sort(key = lambda x: x[0])
to sort the items by the number. This only works if I can delete the # and the empty item and convert the string to a int. I hope someone can help me! Thanks in advance!