Background
I have two lists:
list_1 = ['a_1', 'b_2', 'c_3']
list_2 = [ 'g b 2', 'f a 1', 'h c 3']
Please note that the format of the string elements in the lists is different. In other words, elements of one of the lists are not a subset of the other.
I want to
- Compare the elements of lists 1 and 2, identify elements in list 2 are similar to list 1
- Then I want to sort the list 1 as
['b_2', 'a_1', 'c_3']
in the same order as list 2
Existing questions
- Q1: Here, the elements of one list match exactly with other to some extent '2010-01-01 00:00' and '2010-01'. However, in my case, the formatting may be different.
- Similar case for Q2.
There are several other questions looking into list comparisons, but most of them compare similar strings.
Actual lists
list_1 = ['f_Total_water_withdrawal',
'f_Precipitation',
'f_Total-_enewable_water_resources',
'f_Total_exploitable_water_resources',]
list_2 = ['Precipitation',
'Total-renewable-water-resources',
'Total exploitable water resources',
'Total water withdrawal']