runtime
418 / 500
question 418 pandas Foundations · medium

Order search with optional filters

An admin search page has three optional filters. Write find_orders(records, channel=None, min_total=None, states=None): return the IDs of orders that pass every filter that was given; a filter left as None doesn't restrict anything. min_total is inclusive; states is a list of codes.

Functionfind_orders(records, channel=None, min_total=None, states=None)
Returnsa list of order IDs in their original order
Rulesno filters → every order; an empty states list matches nothing
Examples
callfind_orders([{'order_id': 'O100282', 'customer_id': 'C00077', 'ordered_at': '2024-01-16 13:03:50', 'channel': 'web', 'status': 'delivered', 'promo_code': 'WELCOME10', 'shipping_fee': 5.99, 'total': 35.84, 'ship_state': 'TX'}, {'order_id': 'O100376', 'customer_id': 'C00065', 'ordered_at': '2024-01-21 22:19:23', 'channel': 'web', 'status': 'returned', 'promo_code': 'FREESHIP', 'shipping_fee': 0, 'total': 91.47, 'ship_state': 'CA'}, {'order_id': 'O100918', 'customer_id': 'C01338', 'ordered_at': '2024-02-25 22:28:23', 'channel': 'web', 'status': 'returned', 'promo_code': None, 'shipping_fee': 5.99, 'total': 55.72, 'ship_state': 'NY'}, {'order_id': 'O101219', 'customer_id': 'C00077', 'ordered_at': '2024-03-13 10:01:28', 'channel': 'web', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 246.6, 'ship_state': 'TX'}, {'order_id': 'O101723', 'customer_id': 'C01338', 'ordered_at': '2024-04-06 13:01:04', 'channel': 'phone', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 54.55, 'ship_state': 'NY'}, {'order_id': 'O102603', 'customer_id': 'C01339', 'ordered_at': '2024-05-18 14:45:20', 'channel': 'marketplace', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 5.99, 'total': 17.75, 'ship_state': 'TX'}, {'order_id': 'O103199', 'customer_id': 'C02264', 'ordered_at': '2024-06-12 12:25:00', 'channel': 'app', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 64.17, 'ship_state': 'FL'}, {'order_id': 'O103332', 'customer_id': 'C02315', 'ordered_at': '2024-06-18 23:05:00', 'channel': 'app', 'status': 'cancelled', 'promo_code': None, 'shipping_fee': 5.99, 'total': 25.24, 'ship_state': 'UT'}])returns['O100282', 'O100376', 'O100918', 'O101219', 'O101723', 'O102603', 'O103199', 'O103332']
callfind_orders([{'order_id': 'O100282', 'customer_id': 'C00077', 'ordered_at': '2024-01-16 13:03:50', 'channel': 'web', 'status': 'delivered', 'promo_code': 'WELCOME10', 'shipping_fee': 5.99, 'total': 35.84, 'ship_state': 'TX'}, {'order_id': 'O100376', 'customer_id': 'C00065', 'ordered_at': '2024-01-21 22:19:23', 'channel': 'web', 'status': 'returned', 'promo_code': 'FREESHIP', 'shipping_fee': 0, 'total': 91.47, 'ship_state': 'CA'}, {'order_id': 'O100918', 'customer_id': 'C01338', 'ordered_at': '2024-02-25 22:28:23', 'channel': 'web', 'status': 'returned', 'promo_code': None, 'shipping_fee': 5.99, 'total': 55.72, 'ship_state': 'NY'}, {'order_id': 'O101219', 'customer_id': 'C00077', 'ordered_at': '2024-03-13 10:01:28', 'channel': 'web', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 246.6, 'ship_state': 'TX'}, {'order_id': 'O101723', 'customer_id': 'C01338', 'ordered_at': '2024-04-06 13:01:04', 'channel': 'phone', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 54.55, 'ship_state': 'NY'}, {'order_id': 'O102603', 'customer_id': 'C01339', 'ordered_at': '2024-05-18 14:45:20', 'channel': 'marketplace', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 5.99, 'total': 17.75, 'ship_state': 'TX'}, {'order_id': 'O103199', 'customer_id': 'C02264', 'ordered_at': '2024-06-12 12:25:00', 'channel': 'app', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 64.17, 'ship_state': 'FL'}, {'order_id': 'O103332', 'customer_id': 'C02315', 'ordered_at': '2024-06-18 23:05:00', 'channel': 'app', 'status': 'cancelled', 'promo_code': None, 'shipping_fee': 5.99, 'total': 25.24, 'ship_state': 'UT'}], channel='web')returns['O100282', 'O100376', 'O100918', 'O101219']
callfind_orders([{'order_id': 'O100282', 'customer_id': 'C00077', 'ordered_at': '2024-01-16 13:03:50', 'channel': 'web', 'status': 'delivered', 'promo_code': 'WELCOME10', 'shipping_fee': 5.99, 'total': 35.84, 'ship_state': 'TX'}, {'order_id': 'O100376', 'customer_id': 'C00065', 'ordered_at': '2024-01-21 22:19:23', 'channel': 'web', 'status': 'returned', 'promo_code': 'FREESHIP', 'shipping_fee': 0, 'total': 91.47, 'ship_state': 'CA'}, {'order_id': 'O100918', 'customer_id': 'C01338', 'ordered_at': '2024-02-25 22:28:23', 'channel': 'web', 'status': 'returned', 'promo_code': None, 'shipping_fee': 5.99, 'total': 55.72, 'ship_state': 'NY'}, {'order_id': 'O101219', 'customer_id': 'C00077', 'ordered_at': '2024-03-13 10:01:28', 'channel': 'web', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 246.6, 'ship_state': 'TX'}, {'order_id': 'O101723', 'customer_id': 'C01338', 'ordered_at': '2024-04-06 13:01:04', 'channel': 'phone', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 54.55, 'ship_state': 'NY'}, {'order_id': 'O102603', 'customer_id': 'C01339', 'ordered_at': '2024-05-18 14:45:20', 'channel': 'marketplace', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 5.99, 'total': 17.75, 'ship_state': 'TX'}, {'order_id': 'O103199', 'customer_id': 'C02264', 'ordered_at': '2024-06-12 12:25:00', 'channel': 'app', 'status': 'delivered', 'promo_code': None, 'shipping_fee': 0, 'total': 64.17, 'ship_state': 'FL'}, {'order_id': 'O103332', 'customer_id': 'C02315', 'ordered_at': '2024-06-18 23:05:00', 'channel': 'app', 'status': 'cancelled', 'promo_code': None, 'shipping_fee': 5.99, 'total': 25.24, 'ship_state': 'UT'}], states=['TX'], min_total=17.75)returns['O100282', 'O101219', 'O102603']

Loading your progress…

Order search with optional filters — Python practice · Runtime