I have following condition:
a=[]
for i in list1:
for j in list2:
if i==j:
a.append(i)
I want to add a statement a.append(np.nan) if i!=j after looping through list2.
i.e
After iterating through inner for loop, if i don't find any i==j then it should append nan.
PS.: I have such lists that there will be at-most once i==j.
How to do it?
set2 = set(list2); a = [i if i in set2 else 'nan' for i in list1]