from datetime import datetime costs = [ {"name": 'test', "date": datetime(2025, 6, 22, 17), "value": 10}, {"name": 'test2', "date": datetime(2025, 7, 10, 17), "value": 11}, {"name": 'test3', "date": datetime(2025, 8, 10, 17), "value": 12} ] periods = [ { 'startDate': datetime(2025, 6, 9, 17, 18, 25, 356000), 'endDate': datetime(2025, 7, 10, 17, 18, 25, 356000), 'price': 0.05 }, { 'startDate': datetime(2025, 8, 11, 17, 18, 25, 356000), 'endDate': None, 'price': 0.06 } ] # Verificar se cada cost está dentro de algum período for cost in costs: cost_date = cost['date'] cost_value = cost["value"] matched_period = None for period in periods: start = period['startDate'] end = period['endDate'] if end: if start <= cost_date <= end: matched_period = period break else: if cost_date >= start: matched_period = period break if matched_period: print(f"{cost['name']} está dentro da vigência: preço = {matched_period['price']} | value * cost_value: {cost_value * matched_period['price']}")