Set .add - Adding item to python set

Author: Al-mamun Sarkar Date: 2020-03-24 13:14:19

Set .add() - Adding item to python set. Here is the code to add an item to set in python. This is a solution to a HackerRank Python Sets problem. 

Code:


def distinct_stamps(n):
	stamp = set()
	while n > 0:
		stamp.add( input() )
		n-=1
	return stamp


if __name__ == '__main__':
	n = int( input() )
	print( len(distinct_stamps(n)) )

 

Test Input:

7
UK
Bangladesh
USA
France
Canada
UK
France 

Test Output:

5