Python
What is an iterator in Python?
You have a list of dictionaries with user information. You need to: 1. Filter users older than 18 years 2. Save the filtered data into a single JSON file 3. Create and save a separate file with statistics for all filtered users: - Total number of users - Average age (rounded to 1 decimal place) - Minimum and maximum age users_data = [ { "name": "Alexey", "age": "25", "birth_date": "[phone]", "city": "Moscow" }, { "name": "Maria", "age": "17", "birth_date": "[phone]", "city": "Saint Petersburg" }, { "name": "Ivan", "age": "30", "birth_date": "[phone]", "city": "Moscow" }, { "name": "Elena", "age": "22", "birth_date": "[phone]", "city": "Novosibirsk" }, { "name": "Yves", "age": "9", "birth_date": "[phone]", "city": "..." } ]
Condition: Given two arrays of objects. Each object contains a numeric field 'code'. Return a new array containing all objects from array a for which there exists an object in array b with the same 'code' value. The order of elements in the result is determined by the order of the corresponding 'code' in array b: objects from a should be arranged in the order in which their 'code' appears in b. If multiple objects with the same 'code' appear in b, only the first occurrence is considered. Input data: - a — array of objects of the form { code: number, ...rest }, length from 0 to 10^5 - b — array of objects of the form { code: number, ...rest }, length from 0 to 10^5 Output data: Array of objects from a, filtered and ordered by the first occurrence of the corresponding 'code' in b. Constraints: - 0 <= a.length, b.length <= 100 000 - The 'code' field is a non-negative integer - b may contain duplicate 'code' values — only the first occurrence is considered Example function: ```python # Available without import: json, sys, io def intersect_by_code(a, b): # Write solution here return [] ```
What is the Transactional Outbox pattern?
What is a closure and how is it implemented in Python?
1. Filter users over 18 years old 2. Save the filtered data into a single JSON file 3. Create and save a separate file with statistics for all filtered users: - Total number of users - Average age (rounded to 1 decimal place) - Minimum and maximum age