第26554题 单选题
以下Python代码用于统计字符的后续相邻字符出现次数并按次数降序排序,横线处应填入的代码是?

实现每个字符后紧随字符及其出现次数统计,并对紧随字符按出现次数降序排序,输出形如{'中': [('文', 1), ('国', 2), ('华', 2)]},现有代码如下:

S = """中国华夏中华中华人民共和国中国人中文"""
dictAfter = {}
for i, hz in enumerate(S[1:]):
    tmpDict = dictAfter.get(S[i], {})
    tmpDict[hz] = tmpDict.get(hz, 0) + 1
    dictAfter[S[i]] = tmpDict
dictAfter = { _________________________ for x in dictAfter.items()}
print(dictAfter)
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析