How to create a Python dictionary with double quotes as default quote format?
2016-12-28 16:54
1806 查看
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
相关文章推荐
- xargs: unmatched double quote; by default quotes are special to xargs unless you use the -0 option
- How to create own operator with python in mxnet?
- How to return dictionary keys as a list in Python 3.3
- How can I force Python's file.write() to use the same newline format in Windows as in Linux (“\r\n”
- How to use the date format that has been setup as default in Settings?
- How to create functions that can accept variable number of parameters such as Format
- Python: keep strings in double quote as one word when split string to words
- Conclusion: How to create a color Bitmap with CreateCompatibleBitmap
- How to Create Text Image on the fly with ASP.NET
- How to create your own api with ACL in Magento
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How to create a resizeable dialog box with scroll bars in Visual C++
- how to create dynamically crystal roporter with C# code
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How to create a PictureMarkerSymbol (Picture Symbol)in ArcGIS server with C#
- Python: Best Way to Exchange Keys with Values in a Dictionary?
- how to create a window ot dialog with fixed size?
- How To Create AD Users with PowerShell
- Python: Best Way to Exchange Keys with Values in a Dictionary?
- How To Default To Search Companion With Windows Desktop Search 3