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

How does python format the captured json?

WBOY
Release: 2023-03-01 17:20:01
Original
1172 people have browsed it

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>
Copy after login

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>
Copy after login

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?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template