中级
实现API版本路由
未完成
中级参考
代码结构已给出,请填写 ____ 处
def solve():
from pyodide.http import open_url
from io import StringIO
import pandas as pd
devs_csv = open_url(____).read()
devs = pd.read_csv(StringIO(____))
def route_version(____):
if '____' in path: return '____'
if '____' in path: return '____'
return '____'
def get_device_v1(____):
row = devs[devs['____']==device_id]
if row.empty: return None
return row.iloc[____][['____','____','____']].to_dict()
def get_device_v2(____):
row = devs[devs['____']==device_id]
if row.empty: return None
d = row.iloc[____].to_dict()
d['____'] = '____'; return d
handlers = {'____': get_device_v1, '____': get_device_v2}
paths = ['____', '____', '____']
for path in paths:
ver = route_version(____)
did = path.split(____)[-____]
result = handlers.get(____)(____)
keys = list(result.keys()) if result else []
print(____)
示例
输入
solve()
期望输出
/api/v1/devices/DEV001: ver=v1, fields=['device_id', 'device_name', 'status'] /api/v2/devices/DEV001: ver=v2, fields=['id', 'device_id', 'device_name', 'device_type', 'location_id', 'manufacturer', 'firmware_version', 'status', 'registered_at', 'last_seen_at', '_version'] /api/v1/devices/DEV004: ver=v1, fields=['device_id', 'device_name', 'status']
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199