Секція 2. Розділ 5
single
Challenge: Memory-Efficient Data Pipeline
Свайпніть щоб показати меню
Завдання
Проведіть, щоб почати кодувати
You are building a memory-efficient pipeline that processes a large sequence of transaction records. Your goal is to use the right data structures to minimize memory usage throughout.
You are given the following list of raw transaction tuples:
raw_transactions = [
(1, 4500.0, "USD"),
(2, 1200.5, "EUR"),
(3, 8900.0, "USD"),
(4, 300.75, "EUR"),
(5, 15000.0, "USD"),
]
- Define a class
Transactionwith__slots__ = ("transaction_id", "amount", "currency")and an__init__method that sets all three attributes. - Create a generator expression called
transaction_streamthat yields aTransactioninstance for each tuple inraw_transactions— do not use a list comprehension. - Using
array.arraywith type code"d"(double), create a variable calledusd_amountsthat contains theamountof every transaction wherecurrency == "USD". Consumetransaction_streamto build it. - Print
usd_amounts.
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 5
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат