Introduction to Sets
In this post we going to solving simple [problem from hackerrank python series problems where we just finding average from formula and for this we using set to remove all duplicate items from list.
For this problems we have all things provided we jus need to complete this function. and using this fomula to apply here-
Average = Total Sum of Elements from Array List / Size of Array
A set is an unordered collection of elements without duplicate entries.
When printed, iterated or converted into a sequence, its elements will appear in an arbitrary order.
Problem-Hackerrank
Solution-
Here We have to use Set() because set remove duplicate items from list
Code-
def average(array):# your code goes hereunique_values = set(array) # Convert list#set to remove duplicatestotal = sum(unique_values)average = total / len(unique_values)return average
Put Your Thought or Query Here