2024-10-02 00:40:47 发布
网友
我有一本python词典,如下所示:
dict1 = {'a':1, 'b':2, 'c':3}
到目前为止,我已经在Python 3中运行了以下代码:
for key, value in dict1.items() : print (key* value,end='')
这给了我输出:cccbba
cccbba
我的问题是如何打印-
Your answer : cccba.
像这样:
dict1 = {'a':1, 'b':2, 'c':3} print ("Your answer : ",end='') for key, value in dict1.items() : print (key* value,end='')
你真的应该开始掌握^{}:
>>> print("Your answer: {0}".format("".join([k * v for k, v in dict1.items()]))) Your answer: acccbb
像这样:
你真的应该开始掌握^{} :
相关问题 更多 >
编程相关推荐