Reputation: 19
I have a Multidimensional array:
listPatients = [[ "Johnson", "Fred", "N", "2763 Filibuster Drive",
"Lakeland", "FL", "37643", "Q", "05/27/1935", "164-55-0726", "N"]] \
+ [[ "Williams", "Betty", "L", "701 Collage Avenue",
"Orlando", "FL", "31234", "F", "11/27/1971", "948-44-1038", "Y"]] \
+ [[ "Ling", "Hector", "X", "1500 Raceway Lane",
"Tampa", "FL", "32785", "M", "10/17/2003", "193-74-0274", "Y"]] \
+ [[ "Albin", "Ross", "L", "207 Daisy Avenue",
"Lakeland", "FL", "32643", "M", "12/08/1990", "458-57-2867", "N"]] \
+ [[ "Anderson", "Jason", "O", "1527 Lewis Road",
"Tampa", "FL", "32785", "M", "11/25/1991", "093-50-1093", "Y"]] \
+ [[ "Baca", "Edwin", "L", "25 Hunters Lane",
"Lakeland", "FL", "32643", "M", "10/30/1992", "159-56-9731", "Y"]] \
+ [[ "Birner", "Dalton", "M", "851 Applebe Court",
"Orlando", "FL", "31234", "M", "09/22/1993", "695-21-2340", "Y"]] \
I want to use a for loop to extract the gender in element [7] and change it from "Q" to "M". I am currently using:
gender=["M","F"]
for patients in (listPatients):
if patients[7]!= gender:
print("Patient Gender Error")
print(patients[0],patients[1],patients[2])
patients[7]=input("Please Correct Gender Info:")
else:
()
The output keeps repeating the entire array until its been through. I just want to correct the first list (patient) and be done.
Upvotes: 0
Views: 32
Reputation: 21851
Your problem is the condition if patients[7]!= gender
which tests a string vs a list, which will always be false. This is why the entire list is always printed.
Change this to the not in
test instead:
if patients[7] not in gender:
Upvotes: 1