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

da367344 单选题 共 个子题

实现每个字符后紧随字符及其出现次数统计,并对紧随字符按出现次数降序排序,输出形如{'中': [('文', 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)
A

x[0]: x[1].items().sort(key = lambda x:x[1], reverse = True)

B

x[0]: x[1].items().sort(key = lambda x:x[0], reverse = True)

C

x[0]: sorted(x[1].items(), key = lambda x:-x[0])

D

x[0]: sorted(x[1].items(), key = lambda x:-x[1])

正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧