This file contains hidden or 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
# The given problem was basicly make a count from 1 to 100, and where has a multiple of three, should to have 'Na', | |
# where has a multiple of 5 should to have 'ma' and | |
# where has a multiple of 15 should to have 'nama'. | |
# I made the task by 4 diferent ways | |
# At the end of the file, there is a simple print with a call to each function, just to print the result on the screen | |
# Follow the code | |
# creating a dictionary just to not use magic numbers |
This file contains hidden or 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
# coding: utf-8 | |
import collections | |
def majority_value(data, target_attr): | |
""" | |
Cria uma lista com todos os valores do atributo passado para cada registro | |
e retorna os valores que aparecem com maior frequencia para este atributo | |
""" | |
data = data[:] | |
return most_frequent([record[target_attr] for record in data]) |
NewerOlder