알고리즘/코드워

[python]Sum of positive

(ㅇㅅㅎ) 2020. 4. 15. 20:29
728x90
반응형

https://www.codewars.com/kata/5715eaedb436cf5606000381/train/python

 

Codewars: Train your coding skills

Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.

www.codewars.com

더보기

내 코드

# My Code
def positive_sum(arr):
    sum = 0
    for i in arr:
        if i >= 0:
            sum += i
    return sum
 
# Warriors Code
def positive_sum_(arr):
    return sum(x for x in arr if x > 0)
 
if __name__=='__main__':
    answer = positive_sum([123-1])
    print(answer)
반응형

'알고리즘 > 코드워' 카테고리의 다른 글

[python]Sudoku Solver  (0) 2020.04.17
[python]How do I compare numbers?  (0) 2020.04.16
[python]Permutations  (0) 2020.04.13
[python]Is the string uppercase?  (0) 2020.04.12
[python]Make a spiral  (0) 2020.04.11