본문 바로가기
프로그래밍 문제/[Python] CheckIO

[CheckIO] Majority

by UltraLowTemp-Physics 2021. 3. 11.
728x90

Problem: py.checkio.org/en/mission/majority/
My Solution: 

def is_majority(items: list) -> bool:
    # your code here
    
    return True if items.count(True) > items.count(False) else False


if __name__ == '__main__':
    print("Example:")
    print(is_majority([True, True, False, True, False]))

    # These "asserts" are used for self-checking and not for an auto-testing
    assert is_majority([True, True, False, True, False]) == True
    assert is_majority([True, True, False]) == True
    assert is_majority([True, True, False, False]) == False
    assert is_majority([True, True, False, False, False]) == False
    assert is_majority([False]) == False
    assert is_majority([True]) == True
    assert is_majority([]) == False
    print("Coding complete? Click 'Check' to earn cool rewards!")
728x90

'프로그래밍 문제 > [Python] CheckIO' 카테고리의 다른 글

[CheckIO] Remove All After  (0) 2021.03.22
[Check-IO] Lightbulb Intro  (0) 2021.03.17
[CheckIO] Backward Each Word  (0) 2021.03.10
[Check-IO] Morse Decoder  (0) 2021.03.08
[CheckIO] Solve All the same  (0) 2021.01.07

댓글