Given sets of integers, and , print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either or but do not exist in both.
The first line of input contains an integer, .
The second line contains space-separated integers.
The third line contains an integer, .
The fourth line contains space-separated integers.
Output the symmetric difference integers in ascending order, one per line.
2 4 5 9
2 4 11 12
m, n = [set(input().split()) for i in range(4)][1::2] result = m.difference(n) result.update(n.difference(m)) print(*sorted(map(int, result)), sep = '\n')
Apply your knowledge of the .add() operation to help your friend Rupal.Rupal has a huge collection of country stamps. She decided to count the total number of distinct country stamps in her collection. She asked for your help. You pick the stamps one by one from a stack of country stamps.
Find the total number of distinct country stamps.
The first line contains an integer , the total number of country stamps.
The next lines contains the name of the country where the stamp is from.
Output the total number of distinct country stamps on a single line.
n, stamps = int(input()), set() [stamps.add(input()) for i in range(n)] print(len(stamps))
Set .discard(), .remove() & .pop()
You have a non-empty set , and you have to execute commands given in lines.
The commands will be pop, remove and discard.
The first line contains integer , the number of elements in the set .
The second line contains space separated elements of set . All of the elements are non-negative integers, less than or equal to 9.
The third line contains integer , the number of commands.
The next lines contains either pop, remove and/or discard commands followed by their associated value.
Print the sum of the elements of set on a single line.
1 2 3 4 5 6 7 8 9