본문 바로가기
codeacademy

15. Practice Makes Perfect / median

by 밝게웃다 2017. 3. 28.
1
2
3
4
5
6
7
8
9
10
11
12
def median(lst):
    lst = sorted(lst)
    if len(lst) % 2 ==0:
        print (lst[len(lst)/2-1]+lst[len(lst)/2])/2.0
        return (lst[len(lst)/2-1]+lst[len(lst)/2])/2.0
    else:
        print lst[len(lst)/2]
        return lst[len(lst)/2]
        
        
median([1,1,2])
median([7,3,1,4])
cs


너저분하지만 나름대로 최선을 다한 풀이.

'codeacademy' 카테고리의 다른 글

Time complexity - codility  (0) 2017.03.29
16. Exam Statistics  (0) 2017.03.28
15. Practice Makes Perfect / remove_duplicates  (0) 2017.03.28
15. Practice Makes Perfect / censor  (0) 2017.03.28
15. Practice Makes Perfect / scrabble_score  (0) 2017.03.28

댓글