I have 3 below lists. I want to create an expected_list that has the same shape with list 1 and will contain element in list 2 if the element in list1 has "Review at", otherwise it will be blank ("")
list1 = [ "Review abcd"
"Neu"
"Review defg"
"Review hmk"
"hmd"
"Review lmi"
"Review yuj"
"jmf"
"Review Bad"]
list2 = [ "http1"
"http2"
"http3"
"http4"
"http5"
"http6"]
expected_list = [ "http1"
""
"http2"
"http3"
""
"http4"
"http5"
""
"http6"]
I tried the following code
for idx, item in enumerate(list1):
if "Review" in list1[idx]:
for j in rang(len(list2))
expected_list.append(list2[j])
else:
expected_list.append("")
However, in each element that satisfies the condition, it appends all the element in list2. So the shape of the expected list is more than expected. I know creating the 2nd loop is wrong. But how can i fix it ?
