Created
April 5, 2019 13:32
-
-
Save acwoss/1ab35377ca97bbc018fab4efe12f4e13 to your computer and use it in GitHub Desktop.
ZigzagGlamorousJavabytecode created by acwoss - https://repl.it/@acwoss/ZigzagGlamorousJavabytecode
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
n | NOME | COR | VALOR | |
---|---|---|---|---|
1 | Lapis | Verde | 11,1 | |
2 | Caneta | Vermelho | 12,25 | |
3 | Lapiseira | Azul | 15,45 |
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
import csv | |
import itertools | |
def read_csv(path): | |
with open(path) as stream: | |
reader = csv.DictReader(stream) | |
for row in reader: | |
row['VALOR'] = float(row['VALOR'].replace(',', '.')) | |
yield row | |
data = read_csv('data.csv') | |
combinations = itertools.combinations(data, 2) | |
def sum_of_column_lq(combinations, column, limit): | |
for combination in combinations: | |
sum_of_column = sum(product.get(column, 0) for product in combination) | |
if sum_of_column <= limit: | |
yield combination | |
for i in sum_of_column_lq(combinations, 'VALOR', 25): | |
print([product['NOME'] for product in i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment