I have a list of lists that looks like this one:
big_list = [['12345', 'azs'], ['ABC', 'something'], ['tgrgd', 'ABC'], ['something', '12345']
The lists inside big_list always contain only 2 strings.
I want to sort it as follows:
big_list (or new_list) = [['tgrgd', 'ABC'], ['ABC', 'something'], ['something', '12345'], ['12345', 'azs']]
The second string of a list is equal to the first of next list. It is impossible to have the same string in more than 2 lists, so that won't be a problem.
I am currently addressing the problem by counting occurrences of each string to find the first and last items and then looping through my list to sort it, but I know this is a wrong approach and would like to improve it.