如何获得类似答案的输出?代码是什么。
x={1:"datascience", 2:"Machine learning", 3:"Pythone"}
输出:
{1:{d:1,a:2....}, 2:{M:1,a:2,...},3:{P:1,y:1,..}}
x = {1: "datascience", 2: "Machine learning", 3: "Pythone"}
output = {}
for key in x.keys():
output[key] = {c: i for i, c in enumerate(x[key], start=1)}
print(output)
输出:
{1: {'d': 1, 'a': 4, 't': 3, 's': 5, 'c': 10, 'i': 7, 'e': 11, 'n': 9}, 2: {'M' ....
然而,由于字典不能有重复的密钥,
d a t a b。。在数据库中,第一个和第二个a都有相同的密钥。你想在这里完成什么?