Creating a list of values from json in python -


i have following code in python :

def myprint(d):     date_list = ""       k, v in d.iteritems():         if isinstance(v, dict):             myprint(v)         else:             if (k == "date"):                 date_list = date_list + " " + v       print date_list  firebase = firebase.firebaseapplication('https://my-firebase-db-958b1.firebaseio.com/', none) result = firebase.get('/dublin-ireland', none) myprint(result) 

i'm reading through multi-level json , extracting value key called "date". i'm trying collect dates in json , store them in variable called date_list. when execute code above, date_list variable contains 1 date instance, overwrites in every loop. doing wrong?

you recursing myprint function, date_list variable reassigned empty string. need supply variable input param in function, , need return list instead of printing it.

something this...

def myprint(d, date_list=none):     if not date_list:         date_list = ''      k, v in d.iteritems():         if isinstance(v, dict):             date_list = myprint(v, date_list)         else:             if (k == "date"):                 date_list = date_list + " " + v       return date_list 

why don't want actual list there? there more elegant ways handle that, given information outlined above, believe should @ least working version.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -