문제 보기
Problem
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.
Example
>>> print set() set([])
>>> print set('HackerRank') set(['a', 'c', 'e', 'H', 'k', 'n', 'r', 'R'])
>>> print set([1,2,1,2,3,4,5,6,0,9,12,22,3]) set([0, 1, 2, 3, 4, 5, 6, 9, 12, 22])
>>> print set((1,2,3,4,5,5)) set([1, 2, 3, 4, 5])
>>> print set(set(['H','a','c','k','e','r','r','a','n','k'])) set(['a', 'c', 'r', 'e', 'H', 'k', 'n'])
>>> print set({'Hacker' : 'DOSHI', 'Rank' : 616 }) set(['Hacker', 'Rank'])
>>> print set(enumerate(['H','a','c','k','e','r','r','a','n','k'])) set([(6, 'r'), (7, 'a'), (3, 'k'), (4, 'e'), (5, 'r'), (9, 'k'), (2, 'c'), (0, 'H'), (1, 'a'), (8, 'n')])
Basically, sets are used for membership testing and eliminating duplicate entries.
set을 이용해서 평균값구하기
def average(array):
arr.sort()
print(sum(set(arr))/len(set(arr)))
return(' ')
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
result = average(arr)
print(result)
def average(array):
# your code goes here
a=set(arr)
print(sum(a)/len(a))
return(' ')
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
result = average(arr)
print(result)
def average(array):
array.sort()
average = sum(set(array))/len(set(array))
return average
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
result = average(arr)
print(result)
def average(array):
x=set(array)
y=sum(x)
z=len(x)
result=y/z
return result
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
result = average(arr)
print(result)
'IT & 영상관련 > 파이썬python' 카테고리의 다른 글
(python) 1 부터 n 까지의 연속한 숫자의 합 ( 제곱의 합) (0) | 2020.11.21 |
---|---|
(알고리즘) 계산복잡도 time complexity (0) | 2020.11.21 |
HackerRank] collections.Counter() (저장용) (0) | 2020.08.07 |
HackerRank] Symmetric Difference (저장용) (0) | 2020.08.07 |
HackerRank] .combinations() 조합 (저장용) (2) | 2020.08.06 |