I have a list of lists like the following:
list_of_lists = [
('test_ss', 'Test 1'),
('test_2_ss', 'Test 2'),
('test_3_ss', 'Test 3'),
('test_ss', 'Test 4')
]
I need to sort this list of lists by the first item in each list based on a given variable string.
As an example, I want to sort by 'test_ss' to the resulting list of lists would be:
sorted_list_of_lists = [
('test_ss', 'Test 1'),
('test_ss', 'Test 4'),
('test_2_ss', 'Test 2'),
('test_3_ss', 'Test 3'),
]
I've tried a number of examples off SO and others (Sorting a list of lists based on a list of strings, Sorting lists based on a particular element - Python, sorting multiple lists based on a single list in python, etc) but haven't found the right approach (or I've just not been following those examples correctly.
Any pointers?
test_2_ssshould come beforetest_ss(since2's code is lower thans'). Dosorted(list_of_lists)and see it for yourself