search

Home  >  Q&A  >  body text

python - 包含元组的列表转 JSON,更好的做法?

PHPzPHPz2898 days ago378

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-18 10:02:19

    result = {}
    result['categories'] = []
    for year, month, level, number in rs:
        if level not in result:
            result[level] = [0, 0, 0, 0]
            result[level][month-1] = number
        category = '{0}-{1}'.format(year, month)
        if category not in result['categories']:
            result['categories'].append(category)

    reply
    0
  • Cancelreply