← 返回题库
中级

实现控制指令入队与出队

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd, json
    cmd_csv = open_url(____).read()
    cmds = pd.read_csv(StringIO(____))
    queue_by_device = {}
    for _, row in cmds[cmds['____']=='____'].iterrows():
        queue_by_device.setdefault(____).append(____)
    print(____)
    for did, queue in queue_by_device.items():
        queue.sort(____)
        print("____"+did+"____"+str(len(____))+"____")
        for cmd in queue:
            print("____"+cmd['____']+"____"+str(____)+"____"+cmd['____'])
    print(____)
    for status, grp in cmds.groupby(____):
        print("____"+status+"____"+str(len(____)))

示例

输入
solve()
期望输出
Command queue by device:
  GW-001: 1 pending
    CMD006 [p=1] reboot
All commands status:
  acked: 3
  failed: 1
  pending: 1
  sent: 1
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码