I am building a list in python by looping through some JSON blobs and appending elements. Sometimes the elements are single, sometimes double (or more).
my_list = []
for j in jsons:
my_list.append(j['foo'])
my_list
ends up being ['a1', 'b1', ['c1', 'c2']]
If I use extend instead I get ['a', '1', 'b', '1', 'c1', 'c2']
.
Do I have to first check if what I'm appending is a list, and then append it element-wise? Or is there a better function that already does this?