adding arrays inside dictionaries, inside more arrays.
I asked a question and Jakebird451 helped me. But i have most questions now.
fruits = [{
'name':"apple",
'color':["red","green"],
'weight':1
}, {
'name':"banana",
'color':["yellow","green"],
'weight':1
}, {
'name':"orange",
'color':"orange",
'weight':[1,2]
}, {
'name':"pear",
'color':"orange",
"size" : [
{
"weight" : 4,
"mass" : 1.6
},
{
"weight" : 4,
"mass" : 2
},
{
"weight" : 4,
"mass" : 2.5
}
]
}]
what if there is an another dictionary with an another array?
how do i use this function to get weight and mass?
def findCarByColor(theColor):
array=[]
for x in carList:
if theColor in x['Color']:
array.append(x['name']+" "+x['weight'])
return array
print findit2("red")
If you want to handle both cases, assuming you have the variable
fruitsas in the question:This prints:
While this query:
returns: