好的,如果我有以下内容:
fruits = [{
name:apple,
color:[red,green],
weight:1
}, {
name:banana,
color:[yellow,green],
weight:1
}, {
name:orange,
color:orange,
weight:[1,2]
}]
所以我需要编写一个程序,通过颜色获取重量和名称。有人可以告诉我如何做到这一点。
def findCarByColor(theColor):
z=0
for i in carList:
for a,b in i.iteritems():
#print a,"a", b, "b"
for d in b:
#print d
if d is theColor:
print carList [0][b][0]
return z
print findCarByColor("Red")