This program is used to extract unique elements from a list of nested tuples.
Note that sets are used in this program to keep track of unique elements. Since sets only allow unique values, it ensures that each element is only added to the res list once, even if it appears multiple times in the nested tuples.
val = [(1, 3, 5), (4, 5, 7), (1, 2, 6), (10, 9), (10,)] print("The original ljst : " ,val) res = [] s = set() for i in val: for j in i: if not j in s: s.add(j) res.append(j) print("Unique Element in Nested Tuples : " ,res)
The original ljst : [(1, 3, 5), (4, 5, 7), (1, 2, 6), (10, 9), (10,)] Unique Element in Nested Tuples : [1, 3, 5, 4, 7, 2, 6, 10, 9]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions