So, I have 3 lists as follows:
list_1 = ['a','b','c']
list_2 = ['b','c']
list_3 = [5,4]
I am looking to generate a fourth list of values from list_2 & list_3 that will map to list_1. list_2 and list_3 are independent of list_1 but are subsets of list_1 and do map to each other. i.e list_2 and list_3 is missing item ‘a’ and corresponding values.
I want to handle the missing values and assign some value i.e 0 or empty string. I would like to do this with an inline function. so far, I have tried the following but it fails. What am I doing wrong?
list_4 =[lambda i:list_3[list_2.index(list_1[i])] except "" for i in range(len(list_1))]
My final result should look like this:
list_4=[0,5,4]
Why don’t you check for the presence of the value, instead of relying on exception handling?