I am trying to find the most efficient method of sorting, testing and assignment through a multi-array in python.
Here is a multi array: containing data of users
persons = [['Person 1', 15, 'USA', 'BLACK'],
['Person 2', 12, 'AUS', 'WHITE'],
['Person 3', 34, 'CAN', 'PINK'],
['Person 4', 18, 'CHINA', 'BLUE']]
Here is my code for sorting through. It doesn't work. Result: Getting 'NOT FOUND!'.
persons_profile = []
for i, item in enumerate(persons):
persons_profile .append(item)
if(persons_profile [0] == 'Person 1'):
person_id = persons_profile [0]
person_age = persons_profile [1]
person_country = persons_profile [2]
person_color = persons_profile [3]
print "Person id", persons_profile [O]
some_function()
elif(persons_profile [0] == 'Person 2'):
person_id = persons_profile [0]
person_age = persons_profile [1]
person_country = persons_profile [2]
person_color = persons_profile [3]
print "Person id", persons_profile [O]
some_function()
elif(persons_profile [0] == 'Person 3'):
person_id = persons_profile [0]
person_age = persons_profile [1]
person_country = persons_profile [2]
person_color = persons_profile [3]
print "Person id", persons_profile [O]
some_function()
elif(persons_profile [0] == 'Person 4'):
person_id = persons_profile [0]
person_age = persons_profile [1]
person_country = persons_profile [2]
person_color = persons_profile [3]
print "Person id", persons_profile [O]
some_function()
else:
print "NOT FOUND!"
What is the best way to sort and test if the item 0, 1, 2, 3 in index 0, 1, 2, 3 in the multi-array equal something?