SORT_ORDER = {"DINT": 0, "INT": 1, "BOOL": 2}
mylist.sort(key=lambda val: SORT_ORDER[val[1]])
All we are doing here is providing a new element to sort on by returning an integer for each element in the list rather than the whole list. We could use inline ternary expressions, but that would get a bit unwieldy.
Related Contents:
- Creating numbered list of output
- How do I sort a list of dictionaries by a value of the dictionary?
- Why does “return list.sort()” return None, not the list?
- Sorting list based on values from another list
- How to sort a list/tuple of lists/tuples by the element at a given index?
- How to sort a list of objects based on an attribute of the objects?
- How to sort a dataFrame in python pandas by two or more columns?
- What is the difference between `sorted(list)` vs `list.sort()`?
- What do ellipsis […] mean in a list?
- From list of integers, get number closest to a given value
- Pythonic way to check if a list is sorted or not
- How to sort two lists (which reference each other) in the exact same way
- sort() and reverse() functions do not work
- Why is a list comprehension so much faster than appending to a list?
- Finding median of list in Python
- Combining two sorted lists in Python
- Insert an element at a specific index in a list and return the updated list
- List on python appending always the same value [duplicate]
- Why does ‘.sort()’ cause the list to be ‘None’ in Python? [duplicate]
- Getting only element from a single-element list in Python?
- python filter list of dictionaries based on key value
- Sorting Python list based on the length of the string
- Add list to set?
- How to sort and remove duplicates from Python list? [duplicate]
- Accessing the list while being sorted
- Naturally sorting Pandas DataFrame
- Custom Python list sorting
- Changing an element in one list changes multiple lists [duplicate]
- Does python have a sorted list?
- List sorting with multiple attributes and mixed order
- Sorting a dictionary with lists as values, according to an element from the list
- Insert an item into sorted list in Python
- In Python, why is list[] automatically global? [duplicate]
- Print LIST of unicode chars without escape characters
- Sort a list of lists with a custom compare function
- Sorting list according to corresponding values from a parallel list [duplicate]
- How do I sort a list of objects based on an attribute of the objects?
- Given parallel lists, how can I sort one while permuting (rearranging) the other in the same way?
- Python .sort() not working as expected
- django – convert a list back to a queryset [duplicate]
- How to apply a function to each sublist of a list in python?
- Sort list of strings by a part of the string
- Python data structure sort list alphabetically [duplicate]
- Efficient method to calculate the rank vector of a list in Python
- Skip elements on a condition based in a list comprehension in python
- Unexpected IndexError while removing list items [duplicate]
- Converting string to tuple without splitting characters
- How to sort multidimensional array by column?
- sum each value in a list of tuples
- How to sort a list of dictionaries by a value of the dictionary in Python?