Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in 3rd party category for Majority by NyuuYouGyuu
import pandas as pd
def is_majority(items: list) -> bool:
if len(items) == 0:
return False
it = pd.Series(items)
it = it.value_counts()
if len(it) > 1:
if it.iloc[[0]].values[0] == it.iloc[[1]].values[0]:
return False
return it.iloc[[0]].index[0]
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!")
June 8, 2022
Comments: