Saturday, 1 October 2022

Sample Program from set function Python

This sample task from HackerRank Task.

Now following explanation from the task and solution scrips that I have created:

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.


Task 

Find the total number of distinct country stamps.


Input Format


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 Format

Output the total number of distinct country stamps on a single line.


Sample Input

7

UK

China

USA

France

New Zealand

UK

France 


Sample Output

5


Explanation

UK and France repeat twice. Hence, the total number of distinct country stamps is  (five).


Solution Program :

n = int(input())

val = set()
for i in range(n):
    
    val.add(input())

print (len(val))


Source : HackerRank

No comments:

Post a Comment