names = ['vik', 'zed', 'loren', 'tal', 'yam', 'jay', 'alex', 'gad', 'dan', 'hed']
cities = ['NY', 'NY', 'SA', 'TNY', 'LA', 'SA', 'SA', 'NY', 'SA', 'LA']
ages = ['28', '26', '26', '31', '28', '23', '29', '31', '27', '41']
How do I create a new list with names of all the people from SA?
I tried getting all 'SA' positions and then print the same positions that are in the names list,
pos = [i for i in range(len(names)) if cities[i] == 'SA']
print(names[pos])
Returns the following error:
TypeError: list indices must be integers or slices, not list
I've also attempted to loop over the positions in cities and then do pretty much the same but one by one, but i still wasn't able to put in a list
pos = [i for i in range(len(names)) if cities[i] == 'SA']
x = 1
for i in pos:
x+=1