Introduction to Sets

Sort by

recency

|

632 Discussions

|

  • + 0 comments

    def average(array): # your code goes here k = set(array) result = sum(k)/ len(k) return result

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

  • + 0 comments

    I really liked how it explained the concept clearly and gave a practical problem to apply it. Gold365 login id

  • + 0 comments
    def average(array):
        sum=0
        new_arr=set(arr)
        for i in new_arr:
            sum+=i
        avg=sum/len(new_arr)
        rounded=round(avg,3)
        return rounded
    
    if __name__ == '__main__':
        n = int(input())
        arr = list(map(int, input().split()))
        result = average(arr)
        print(result)
    
  • + 0 comments

    Here is HackerRank Introduction to sets in python solution - https://programmingoneonone.com/hackerrank-introduction-to-sets-solution-in-python.html

  • + 0 comments
    # The sum of the set of the array is divided by the length of the set of the array and then rounded to three decimal places.
    
    def average(array):
        avg = sum(set(array)) / len(set(array))
        return round(avg, 3)