Created
February 10, 2020 07:05
-
-
Save nclv/8b8ec67af58431c9166b0470c4fb873b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from more_itertools import ilen | |
def nombre_occurrences(liste, element): | |
return ilen(filter(lambda el: el == element, liste)) | |
def element_maj(liste): | |
return next(filter(lambda element: nombre_occurrences(liste, element) > len(liste)//2, liste), None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compte = defaultdict(int) | |
foe element in liste: | |
compte[element] += 1 | |
maj = max(compte.keys(); key=lambda k: compte[k]) | |
if compte[maj] > len(liste): | |
return maj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment