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 dictionary implementation
Python dictionary implementation http://www.laurentluce.com/posts/python-dictionary-implementation/ ...
- Python dictionary 字典 常用法
Python dictionary 字典 常用法 d = {} d.has_key(key_in) # if has the key of key_in d.keys() ...
- python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决
有如下一个文件,内容如下 { "test1": "/root/test/test1.template", "test2": "/r ...
- JSON parser error with double quotes
Use backslash charater \ to escape double quotes in JSON file as below example. { "myInfo" ...
- python基础_格式化输出(%用法和format用法)(转载)
python基础_格式化输出(%用法和format用法) 目录 %用法 format用法 %用法 1.整数的输出 %o -- oct 八进制%d -- dec 十进制%x -- hex 十六进制 &g ...
- python实现float/double的0x转化
1. 问题引出 最近遇到了一个小问题,即: 读取文本文件的内容,然后将文件中出现的数字(包括double, int, float等)转化为16进制0x存储 原本以为非常简单的内容,然后就着手去写了py ...
- sort a Python dictionary by value
首先要明确一点,Python的dict本身是不能被sort的,更明确地表达应该是"将一个dict通过操作转化为value有序的列表" 有以下几种方法: 1. import oper ...
- python : dictionary changed size during iteration
1. 错误方式 #这里初始化一个dict >>> d = {'a':1, 'b':0, 'c':1, 'd':0} #本意是遍历dict,发现元素的值是0的话,就删掉 >> ...
- PythonStudy——Python字典底层实现原理 The underlying implementation principle of Python dictionary
在Python中,字典是通过散列表或说哈希表实现的.字典也被称为关联数组,还称为哈希数组等.也就是说,字典也是一个数组,但数组的索引是键经过哈希函数处理后得到的散列值.哈希函数的目的是使键均匀地分布在 ...
随机推荐
- asp.net 正则获取url参数
现在有一种场景:Url是数据库里面的,里面带有很多参数,如何获取具体参数的值呢? var uri = new Uri(pageUrl); var queryString = uri.Query; va ...
- 【BZOJ 1016】【JSOI 2008】最小生成树计数
http://www.lydsy.com/JudgeOnline/problem.php?id=1016 统计每一个边权在最小生成树中使用的次数,这个次数在任何一个最小生成树中都是固定的(归纳证明). ...
- pip安装使用详解(转)
pip类似RedHat里面的yum,安装Python包非常方便.本节详细介绍pip的安装.以及使用方法. 1.pip下载安装 1.1 pip下载 1 # wget "https://py ...
- wpf xaml文件编辑出现中文乱码
突然有一天,发现在xaml文件编辑窗里打汉字出来了乱码...抓狂 结果发现是番茄助手搞得鬼.只能在编辑xaml文件是暂时关闭番茄助手 visual assist
- 【转】MipMap
原文地址http://www.cppblog.com/wc250en007/archive/2011/08/06/152653.html 首先从MIPMAP的原理说起,它是把一张贴图按照2的倍数进行缩 ...
- form 表单跨域提交
<!DOCTYPE html><html> <head> <title>form 表单上传文件</title> <script src ...
- sql查询,不在某一范围问题的新思路
新思路: A为学生表 B为中间表(学生和课程的) C为课程表 新的思路是用left join,(right join应该也可以) 查询没有选课的学生 ... C left join B on A.si ...
- Pi 前2600位
3.14 15926 53589 79323 84626 43383 27950 28841 97169 39937 51058 2097 4944 5 92307 81640 62862 0899 ...
- UVA725
虽然是暴力求解,但是也要观察条件,尽量提高效率.如本题,原本要枚举10个数,但是分析可知通过枚举fghij就可以了. #include<stdio.h> #include<strin ...
- Spring(Model)
一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架 分层架构,一站式(full-stack),高内聚低耦合,允许客户端JavaScript远程调用服务端JAVA类方法 应用中的对象不依赖于S ...