Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
72 views
in Technique[技术] by (71.8m points)

python - How do i extract inner dictionary from outer list

I need to extract the inner dictionary from outer list ie remove the outer square brackets of the list.

example:

myList =[{'a':'1','b':'2','c':'3'},{'d':'4','e':'5'}]

Desire output:

{'a':'1','b':'2','c':'3'},{'d':'4','e':'5'}

Please note that inner dictionaries can be of dynamic size.

Any help would be great.

question from:https://stackoverflow.com/questions/65839754/how-do-i-extract-inner-dictionary-from-outer-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just accessing the list element by index.

myList =[{'a':'1','b':'2','c':'3'},{'d':'4','e':'5'}]
d = myList[0]

So if you have k dictionaries in the list you need to access all of them, but this will be tedious.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...