Write a Python program to check if a specified element presents in a tuple of tuples.

Original list:
(('Red', 'White', 'Blue'), ('Green', 'Pink', 'Purple'), ('Orange', 'Yellow', 'Lime'))

Check if White present in said tuple of tuples!
True
Check if White present in said tuple of tuples!
True
Check if Olive present in said tuple of tuples!
False

Program:-

colors_tuple=(('Red', 'White', 'Blue'), ('Green', 'Pink', 'Purple'), ('Orange', 'Yellow', 'Lime'))#original tuple
def investigate_tuples(colors, c): # if the color is present in the tuples of tuple then return true else false
    for i in range(0,len(colors)):
        for j in range(0,len(colors)):
            if(colors[i][j]==c):
                return True
    return False

print("Original list: ")
print(colors_tuple)
temp=('White','White','Olive')

for i in range(0,len(temp)):
    print("\nCheck if", temp[i], "present in said tuple of tuples!")
    print(investigate_tuples(colors_tuple, temp[i])) #O/P according to the question

Output:-

Program Explanation:-
colors_tuple contains orignal tuples of tuple provided in the question. 
function investigate_tuples(colors,c) checks whether the color is present in colors_tuple, if color is present then return true else return false.Thereby, Original List is printed. temp tuple contains values 'White','White','Olive'. 
for loop in the end simply print the information whether the color is present in the colors_tuple by calling investigate_tuples(colors,c) method side by side.

Comments