w = {'astronomy': {'sunrise': u'7:24 am', 'sunset': u'5:30 pm'}, 'atmosphere': {'humidity': u'71', 'pressure': u'30.26', 'rising': u'2', 'visibility': u'10'}, 'condition': {'code': u'34', 'date': u'Mon, 02 Feb 2015 11:53 am CST', 'temp': u'2', 'text': u'Fair', 'title': u'Conditions for Ames, IA at 11:53 am CST'}, 'forecasts': [{'code': u'30', 'date': u'2 Feb 2015', 'high': u'13', 'low': u'5', 'text': u'Partly Cloudy'}, {'code': u'26', 'date': u'3 Feb 2015', 'high': u'26', 'low': u'8', 'text': u'Cloudy'}, {'code': u'14', 'date': u'4 Feb 2015', 'high': u'18', 'low': u'-6', 'text': u'AM Snow Showers'}, {'code': u'32', 'date': u'5 Feb 2015', 'high': u'17', 'low': u'9', 'text': u'Sunny'}, {'code': u'30', 'date': u'6 Feb 2015', 'high': u'37', 'low': u'26', 'text': u'Partly Cloudy'}], 'geo': {'lat': u'41.99', 'long': u'-93.62'}} print "Answer 1:", w count = {} for element in w: count[element] = count.get(element, 0) + 1 print "Answer 2:", count print "Answer 3:", w.keys() #print "Answer4a: Value : %s" % w.get('forecasts') fc = w['forecasts'] print "Answer 4:", fc print "Answer 5: fc is a dictionary" first_day = fc[0:2] print "Answer 6:", first_day print "Answer 7: first_day is of type list and it is inside a dictionary (fc), which is inside a dict (w)" print "Answer 8:" print "Answer 9:" print "Answer 10:" print "Answer 11"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question