Skip to content

Instantly share code, notes, and snippets.

@acwoss
Created April 5, 2019 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acwoss/1ab35377ca97bbc018fab4efe12f4e13 to your computer and use it in GitHub Desktop.
Save acwoss/1ab35377ca97bbc018fab4efe12f4e13 to your computer and use it in GitHub Desktop.
ZigzagGlamorousJavabytecode created by acwoss - https://repl.it/@acwoss/ZigzagGlamorousJavabytecode
n NOME COR VALOR
1 Lapis Verde 11,1
2 Caneta Vermelho 12,25
3 Lapiseira Azul 15,45
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