zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    爬虫基础 2.1 http原理
    爬虫基础 2.1 http原理
    3.29上午
    3.28
    3.27下午
    3.27上午
    3.24上午
    3.23下午
    3.23上午
    3.22上午
  • 原文地址:https://www.cnblogs.com/pinganzi/p/6230106.html
Copyright © 2011-2022 走看看