I'm trying to do this program that tells me in which list I can find a "part" or value that I'm looking for. I need to get the name of the list in which the part is found. Each list is a location for the parts, and I made a list of lists to traverse through it all in a loop.
list1=[1,5,8,3,9]
list2=[18,56,82,31,91]
list3=[10,51,2,4,70]
lists=[list1, list2, list3]
def lookPart():
part = int(input("What part are you looking for? "))
for l in lists:
for i in l:
if i==part:
print("Your part is here: ", l)
while 1:
lookPart()
print("")
Assuming Im looking for part 5:
I expect it to print:
Your part is here: list1
But instead I get:
Your part is here: [1,5,8,3,9]
EDIT: Thank you to all those of you who suggested using a dictionary. I will do that, but is there a way to create the dictionary using a loop? I will be dealing with a couple of hundred lists so making a dictionary manually would be very time-consuming.