Introduction to Sets - Python sets

Introduction to Sets - Python sets

Instructor-svgAl-Mamun Sarkar
Mar 24 , 2020

Introduction to Sets problem's solution. This is the solution to a HackerRank problem. Click here to see the problem.

Code:


def average(arr):
	arr_set = set(arr)
	return sum(arr_set)/len(arr_set)

if __name__ == '__main__':
	n = int( input() )
	arr = list( map( int, input().split() ) )
	result = average(arr)
	print(result)

 

Test Input:

10
161 182 161 154 176 170 167 171 170 174

Test Output:

169.375
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram