在Python中加入字典操作 [英] Join Operation for Dictionary in Python
本文介绍了在Python中加入字典操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
步骤1.i/p ="wwwwaaadexxxxxx"
Step 1. i/p= "wwwwaaadexxxxxx"
步骤2.converted= {'w':4,'a':3,'d':1,'e':1,'x':6}
Step 2. converted= {'w': 4, 'a': 3, 'd': 1, 'e': 1, 'x': 6}
最后一步.o/p ='w4a3d1e1x6'
Step Final. o/p= 'w4a3d1e1x6'
我在S2上如何进入最后一步?
I'm on S2 how to go to final step ?
请欣赏直接转化1->最终
Would appreciated direct conversions 1-> Final
时间复杂度应该较小,但会感激任何Sol.
Time Complexity should be less but would appreciate any Sol.
我想以存储在任何变量中的String形式返回
I want to return in form of String stored in any var
不导入任何内容
推荐答案
您可以使用理解(但是您需要将这些数字转换为字符串),请尝试以下代码:
You could use a comprehension(But you need to convert those numbers to string), Try code below:
converted = {'w': 4, 'a': 3, 'd': 1, 'e': 1, 'x': 6}
print("".join([str(char) for k, v in converted.items() for char in (k, v)]))
这篇关于在Python中加入字典操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文