I have two lists with string values, list1 = ['a','g','f','e']
and list2 = [['c','v','d'], ['a','d','e'], ['g','h']]
. I want to write a code, that will append list1
into list2
only if first (0th) element in nested list of list2 is not the same as first (0th) element from list1
.
This is the code that I wrote, it does not have errors, but It does not do what I want
list1 = ['a','g','f','e']
list2 = [['c','v','d'], ['a','d','e'], ['g','h']]
print('List 1: ', list1)
print('List 2: ', list2)
for nest in list2:
if list1[0] != nest[0]:
list2.append(list1)
print(list2)
else:
print("Not added")