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!!!)
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?