(a + b == c or a + c == b or b + c == a)를 제일 짧게 써주세요

조회수 2027회

발생하는 문제 및 실행환경

a + b == c or a + c == b or b + c == a 제일 짧은 코드로 표현하려고 합니다.

제가 생각할 수 있는건 여기까지가 한계인데 근데 제가 짠게 맞긴 한건지 좀 불안하기도하고 그래서 더 좋은 방법이 있을지 궁금합니다

소스코드

a + b + c in (2*a, 2*b, 2*c)

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    제가 추천하는 건 a + b == c or a + c == b or b + c == a를 그냥 그대로 쓰는 겁니다.

    저 코드는 짧지만 pythonic 코드가 아니기 때문입니다. python zen을 보면(this 모듈에 있습니다)

    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren't special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    Now is better than never.
    Although never is often better than right now.
    If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea -- let's do more of those!
    

    $ 파이썬 코드는 간단하고, 간결하고, 설명하기 쉬워야 합니다.

    a + b + c in (2*a, 2*b, 2*c)가 맞는진 확인하지 않았으나, 설령 맞다고 하더라도 다른 사람이 이 코드를 보고 뭘 하는건지 이해할 수 있을까요?

    짧은 코드가 파이썬에 장점이지만, 그렇다고 해서 너무 길이에 집착하지 않아도 됩니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)