/
Oxanita
/
Homework_1
Обзор
Документация
Войти
/
Oxanita
/
Homework_1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/processing.py
28 строк
1 KB
Oxana-Bobrysheva
Module MAIN was added and other modules were fixed
31 окт 2024, 23:50
31 окт 2024, 23:50
be83987
Код
Авторство
О чём код?
from src.reading_csv import read_financial_operations def filter_by_state(cards_information: list, status: str = "EXECUTED") -> list: """Function that takes the list of dictionaries and returns a new list of only those dictionaries in which the key "state" matches the indicated value. """ filtered_list = [] for card_information in cards_information: if card_information.get("state") == status: filtered_list.append(card_information) else: continue return filtered_list def sort_by_date(cards_information: list, reverse: bool = True) -> list: """Function that takes the list of dictionaries and returns the sorted list of dictionaries by date.""" sorted_list_of_dictionaries = sorted(cards_information, key=lambda x: x["date"], reverse=reverse) return sorted_list_of_dictionaries if __name__ == "__main__": file_path = "../data/transactions.csv" transactions = read_financial_operations(file_path) print(filter_by_state(transactions, "PENDING")) print(transactions)