Home  >  Article  >  Backend Development  >  How does python format the captured json?

How does python format the captured json?

WBOY
WBOYOriginal
2016-12-01 00:25:381120browse

I encountered this situation, that is, the captured data was ten [{'1′: 'a','3′: 'c','2′: ''},{'1′: ' a','3′: 'c','2′: ''},{'1′: 'a','3′: 'c','2′: ''},...] like this data (because ten pages of data were captured), I now want to merge all the dicts in these ten pages into one variable, which can be organized into array0=>'a' just like the array in php Data structure, how to do it?

(Speaking of which Python tutorial on data structure is better? I really feel that Python’s data structures are not as convenient as PHP’s arrays!!!)

Reply content:

I encountered this situation, that is, the captured data was ten [{'1′: 'a','3′: 'c','2′: ''},{'1′: ' a','3′: 'c','2′: ''},{'1′: 'a','3′: 'c','2′: ''},...] like this data (because ten pages of data were captured), I now want to merge all the dicts in these ten pages into one variable, which can be organized into array0=>'a' just like the array in php Data structure, how to do it?

(Speaking of which python tutorial on data structure is better? I really think that python’s data structures are not as convenient as php’s arrays!!!)

Just add it to an array variable:

<code class="python">lst = []
jsn_data = [{'1': 'a', '3': 'c', '2': ''}, {'1': 'a', '3': 'c'}]
lst.append(jsn_data)</code>

Python’s data structure is very convenient, such as the example you gave:

<code>lst = [{'1':'a','3':'c','2': ''},{'1': 'a','3': 'c','2': ''},{'1': 'a','3': 'c','2': ''}]

lst[0]       #值为 {'1':'a','3':'c','2':''}
lst[0]['1']  #值为 'a'
let[0]['3']  #值为 'c'
let[0]['2']  #值为 ''</code>

I remember that python list has a merge function extend, and finally it is used with set to remove duplicates

Can you explain what is the expected result you want?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn