How to create a Python dictionary with double quotes as default quote format?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How to create a Python dictionary with double quotes as default quote format?相关的知识,希望对你有一定的参考价值。

couples = [
               [jack, ilena], 
               [arun, maya], 
               [hari, aradhana], 
               [bill, samantha]]
pairs = dict(couples)

print pairs的结果为:

{arun: maya, bill: samantha, jack: ilena, hari: aradhana}

方法一:

import json
json.dumps(pairs)

 

方法二:

print {%s} % , .join(["%s": "%s" % (k, v) for k, v in pairs.items()])

 

 

转自: http://stackoverflow.com/questions/18283725/how-to-create-a-python-dictionary-with-double-quotes-as-default-quote-format

以上是关于How to create a Python dictionary with double quotes as default quote format?的主要内容,如果未能解决你的问题,请参考以下文章

python 从django modelhttp://stackoverflow.com/questions/7514964/django-how-to-create-a-file-and-save-

How to create a test plan

How difficult is it to create a JavaScript framework?

[转]How to: Create a Custom Principal Identity

How to create vlan on Linux (with Cisco Catalyst Switch)

How to create a repository in Github with Eclipse?