I have 1 master list which is based on 2 child lists. I want to create a function with "search_value" parameter & would like to print the index position of the "search_value" item including the list index of child list.
Example:
grocery = ["Juice", "Tomato", "Potato", "Banana", "Milk", "Bread"]
clothes = ["Shirt", "Pant", "Jacket", "Sweater", "Hat", "Pajama", "T-Shiraz", "Polo"]
master_list = [grocery, clothes]
Expected result :
"The Item You Searched For is", search_value, ". It is in the first/second list with index position of:", index #
I am new to python & have written the working code. Just want to know how to do it with less effort
def function(in_coming_string_to_search):
grocery = ["Juice", "Tomato", "Potato", "Banana", "Milk", "Bread"]
clothes = ["Shirt", "Pant", "Jacket", "Sweater", "Hat", "Pajama", "T-Shiraz", "Polo"]
master_list = [grocery, clothes]
length = int(len(master_list))
print master_list, "List has:", length, "list items", '\n'
to_do_list_first_array_index = 0
counter = 0
list_one_length = int(len(master_list[0]))
while counter < list_one_length:
for a in master_list[to_do_list_first_array_index]:
# print a
if a == in_coming_string_to_search:
print "The Item You Searched For is", in_coming_string_to_search, ". It is in the first list with index position of:", counter
counter = counter + 1
to_do_list_second_array_index = 1
counter2 = 0
list_two_length = int(len(master_list[1]))
while counter2 < list_two_length:
for b in master_list[to_do_list_second_array_index]:
if b == in_coming_string_to_search:
print "The Item You Searched For is", in_coming_string_to_search, ". It is in the second list with index position of:", counter2
counter2 = counter2 + 1
if __name__ == '__main__':
string_to_search = "Tomato"
function(string_to_search)