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?的更多相关文章

  1. Python dictionary implementation

    Python dictionary implementation http://www.laurentluce.com/posts/python-dictionary-implementation/ ...

  2. Python dictionary 字典 常用法

    Python dictionary 字典 常用法 d = {} d.has_key(key_in)       # if has the key of key_in d.keys()          ...

  3. python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决

    有如下一个文件,内容如下 { "test1": "/root/test/test1.template", "test2": "/r ...

  4. JSON parser error with double quotes

    Use backslash charater \ to escape double quotes in JSON file as below example. { "myInfo" ...

  5. python基础_格式化输出(%用法和format用法)(转载)

    python基础_格式化输出(%用法和format用法) 目录 %用法 format用法 %用法 1.整数的输出 %o -- oct 八进制%d -- dec 十进制%x -- hex 十六进制 &g ...

  6. python实现float/double的0x转化

    1. 问题引出 最近遇到了一个小问题,即: 读取文本文件的内容,然后将文件中出现的数字(包括double, int, float等)转化为16进制0x存储 原本以为非常简单的内容,然后就着手去写了py ...

  7. sort a Python dictionary by value

    首先要明确一点,Python的dict本身是不能被sort的,更明确地表达应该是"将一个dict通过操作转化为value有序的列表" 有以下几种方法: 1. import oper ...

  8. python : dictionary changed size during iteration

    1. 错误方式 #这里初始化一个dict >>> d = {'a':1, 'b':0, 'c':1, 'd':0} #本意是遍历dict,发现元素的值是0的话,就删掉 >> ...

  9. PythonStudy——Python字典底层实现原理 The underlying implementation principle of Python dictionary

    在Python中,字典是通过散列表或说哈希表实现的.字典也被称为关联数组,还称为哈希数组等.也就是说,字典也是一个数组,但数组的索引是键经过哈希函数处理后得到的散列值.哈希函数的目的是使键均匀地分布在 ...

随机推荐

  1. 利用StringEscapeUtils对字符串进行各种转义与反转义(Java)

    apache工具包common-lang中有一个很有用的处理字符串的工具类,其中之一就是StringEscapeUtils,这个工具类是在2.3版本以上加上的去的,利用它能很方便的进行html,xml ...

  2. 关于mirai病毒的一些研究

    首页好像只能显示随笔,之前发在文章里面的,见文章http://www.cnblogs.com/mrchang/articles/6210681.html

  3. 关于CAJViewer 无法获取document路径问题

    修改注册表 进入注册表编辑器: win+R >>输入 regedit  如下图: 修改关键注册表项(两项相同值应同时修改) 1.HKEY_CURRENT_USER\Software\Mic ...

  4. Android基础测试题(四)

    看了前两道题大家有没有发现,测试题少了(一),大家猜猜测试题(一)是什么? Android基础测试题(四): 需求: 建一个方法,格式化输出2016-11-14 10:15:26格式的当前时间,然后截 ...

  5. html5拖拽事件 xhr2 实现文件上传 含进度条

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  6. UVA1625Color Lenth(DP+LCS变形 未AC)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/C 紫书P276 res[i][j]表示第一个序列移动i个,第 ...

  7. Sonar安装配置

    https://www.sonarqube.org/downloads/ 下载sonar.当前版本为6.2 解压压缩包,进行配置: 修改sonarqube-6.2\conf\sonar.propert ...

  8. DPM模型简单记录

    这个模型思想很直观(有误),但是写的源码太难懂了(看的是release-3的版本,最接近Object Detection with Discriminatively Trained Part Base ...

  9. 在thinkphp中js文件添加路径

    JS文件不认识__URL__这些tp独特的链接,所以要自己重新定义url,才能使用这些路径. 在js对于的模板上定义url 然后在js文件中引用

  10. H5+CSS3知识点

    概要:CSS3美化样式.自定义字体图标.滤镜设置.CSS3选择器.transform2D转换.新增表单控件.vaild表单验证.表单样式美化等. 属性选择器: E[attr]只使用属性名,但没有确定任 ...