I have a list which looks like this:
List = [['name1','surname1'], ['name2','surname2'],['name3','surname3']]
I would like to check if "name1" is in the object "List". I have tried:
if 'name1' in List:
print True
else:
print False
and the output is 'False'. Any idea how to create a sublist (or something similar) to check the first element of every sub-list without looping through all the elements of the main list?
POSSIBLE SOLUTION
What I have thought about is:
for i in range(0, len(List)):
if List[i][0] == 'name1':
print True
but I want to avoid exactly this iteration with something more optimized, if possible.