I have several dictionaries( Class1 , Class2
) , and one element of the dictionary stores a list (Score
) , I want to put the element of the list into another list , but not the list itself to another list .
I try the following code
All = []
Class1 = {"name":"A","score":[60,70,80]}
Class2 = {"naem":"B","score":[70,80,90]}
All.append(Class1['score'])
All.append(Class2['score'])
print(All)
but the result is
[[60, 70, 80], [70, 80, 90]]
but what I want is
[60, 70, 80, 70, 80, 90]
I try this solution below , but I want to know does there exists better solution?
All = []
Class1 = {"name":"A","score":[60,70,80]}
Class2 = {"naem":"B","score":[70,80,90]}
Scores1 = Class1['score']
Scores2 = Class2['score']
Scores = Scores1 + Scores2
for score in Scores:
All.append(score)
print(All)
thanks