← 返回 coinbase 的题目列表Filter Transactions From List
类型:online_judge
Given a list of transactions where each transaction includes a date, user ID, and amount. Some filter conditions such as a specific date range, specific user IDs, etc., are also provided. Write a function to return a list of transactions that meet the filter conditions.
Input:
A list of transactions, each including a date (string format, e.g., 'YYYY-MM-DD'), user ID (integer), and amount (float).
Filter conditions, including:
Date range (start date and end date as strings)
List of user IDs to keep
Minimum and maximum amounts inclusive
Output:
A list of transactions that satisfy all conditions.
Example:
transactions = [
{'date': '2023-01-01', 'userId': 1, 'amount': 100.0},
{'date': '2023-01-02', 'userId': 2, 'amount': 150.0},
{'date': '2023-01-03', 'userId': 1, 'amount': 200.0}
]
filters = {
'date_range': ('2023-01-01', '2023-01-02'),
'user_ids': [1],
'amount_range': (100.0, 200.0)
}
# Expected output: [{'date': '2023-01-01', 'userId': 1, 'amount': 100.0}]
Data scale: The transaction list may contain up to 10,000 records.
Example
Input
{'transactions': [{'date': '2023-01-01', 'userId': 1, 'amount': 100.0}, {'date': '2023-01-02', 'userId': 2, 'amount': 150.0}, {'date': '2023-01-03', 'userId': 1, 'amount': 200.0}], 'filters': {'date_range': ('2023-01-01', '2023-01-02'), 'user_ids': [1], 'amount_range': (100.0, 200.0)}}