我正在编写一个接受1个参数的函数,我希望该参数是一个列表。
我基本上已经得到了我想要的所有行为,除了或一件事:`
def index_responses(a):
j = {}
count = 0
key = 0
for y in a:
j["Q",key]=a[count]
count+=1
key+=1
print(j)
return a
以下是函数调用:
print(index_responses(['a', 'b', 'c']))
print(index_responses(['d','d','b','e','e','e','d','a']))
我的输出是:
{('Q', 0): 'a', ('Q', 1): 'b', ('Q', 2): 'c'}
{('Q', 0): 'd', ('Q', 1): 'd', ('Q', 2): 'b', ('Q', 3): 'e', ('Q', 4): 'e', ('Q', 5): 'e', ('Q', 6): 'd', ('Q', 7): 'a'}
但我需要我的输出看起来更干净,更像:
(Q1:'A',Q2:'B'(等…)
如何清理输出?
谢谢你的回复。