python 2.7 - Assign array value to local variable -
i fetching records , contains array contains 2 further fields. example, fetched data this:
{"id": 1, "name": "govind", "array": [{"subject": "maths", "score": 70}, {"subject": "maths", "score": 80}, {"subject": "english", "score": 90}]}
i want assign value of "score"
local variable "subject"
"maths"
, can have this:
var1 = 70 , var2 = 80
code snap:
try : cursor = db.students.find().sort('_id',pymongo.ascending) loop in cursor: item in loop: if loop[item] "type": #here need check value of array elements , remove them array. print key #loop[item]
first loop gives me record. second loop loops on item of 1 array further need access array elements , comparison lower value.
the output this
**193 govind [{u'score': 47 , u'type': u'exam'}, {u'score': 41 , u'type': u'quiz'}, {u'score': 70 , u'type': u'homework'}, {u'score' : 48 , u'type': u'homework'}]**
got solution.
loop on array , access elements using
loopindex[key]
Comments
Post a Comment