Python Program to print the lists of unique elements in the given lists

 Write a program to print the lists which contain the unique elements in the given list of lists.

Input

The first line of input will contain a positive integer (N).
The next N lines will contain space-separated integers, denoting elements of each list.

Output

The output should be a single line containing the list of lists with unique elements in the order of inputs given.

Explanation

For example, if the given N is 3, read the inputs in the next three lines. If the inputs in the next three lines are the following.

1 2 3
5 10 15
10 20 10 30

As the third list contains duplicate elements, the output list should not contain the third list. So the output should be

[[1, 2, 3], [5, 10, 15]]

Sample Input 1
4
1 2 3 3 4
2 3 4 5
10 20 30
3 6 9 12 3

Sample Output
[[2, 3, 4, 5], [10, 20, 30]]

Code:

n = int(input())
num_list = []
for i in range(n):
    values_list = list(map(int,input().split()))
    values_set = set(values_list)
    is_equal = len(values_list) == len(values_set)
    if is_equal:
        num_list.append(values_list)
print(num_list)

Input
4
4 6 7 8 4
5 6 5 8 9
3 23 10 12
12 4 6 7 5

Output
[[3, 23, 10, 12], [12, 4, 6, 7, 5]]

Comments

Popular posts from this blog

CODING ASSIGNMENT 4

CODING PRACTICE 11 Music Page

CCBP Static Website Coding Assignment 2 Solution | Yoga Page