Set Add() in Python - HackerRank Solution
Problem :
It adds the element to the set and returns 'None'.
Example :
>>> s = set('HackerRank') >>> s.add('H') >>> print s set(['a', 'c', 'e', 'H', 'k', 'n', 'r', 'R']) >>> print s.add('HackerRank') None >>> print s set(['a', 'c', 'e', 'HackerRank', 'H', 'k', 'n', 'r', 'R'])
Task :
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 N country stamps.
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 N country stamps.
Find the total number of distinct country stamps.
Input Format :
The next N lines contains the name of the country where the stamp is from.
Constraints :
- 0 < N < 1000
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 5 (five).
Solution :
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Set.Add() in Python - Hacker Rank Solution # Python 3 # Enter your code here. Read input from STDIN. Print output to STDOUT # Set.Add() in Python - Hacker Rank Solution START N = int(input()) countries = set() for i in range(N): countries.add(input()) print(len(countries)) # Set.Add() in Python - Hacker Rank Solution END |
Disclaimer :-
the above hole problem statement is given by hackerrank.com but the solution is generated by the codeworld19 authority if any of the query regarding this post or website fill the following contact form thank you.
Such brilliant and complete knowledgeable post I was finding so many time finally I got it
learn programming language
A popular programming and development blog. Here you can learn C, C++, Java, Python, Software engineering, ML, AI, Software Developers
learn programming tutorials
online job service provider blog. Job seekers are requested to apply online through direct link before it gets expired
latest freshers jobs jobs
Free Recharge Tricks 2021, Loot Tricks, Paytm Freebies Sample, Mobile App Offer Unlimited UPI Cash, Best Deals Of The Day. 4G Internet
Latest deal and mobile offer
Such brilliant and complete knowledgeable post I was finding so many time finally I got it
http://codeworld19.com/
A popular programming and development blog. Here you can learn C, C++, Java, Python, Software engineering, ML, AI, Software Developers
https://www.chase2learn.com/
online job service provider blog. Job seekers are requested to apply online through direct link before it gets expired
https://freshersworkjob.com/
Free Recharge Tricks 2021, Loot Tricks, Paytm Freebies Sample, Mobile App Offer Unlimited UPI Cash, Best Deals Of The Day. 4G Internet
https://www.loottricks.in/