Extracting and summing student scores from a JSON file using Python 2.7.10
Pete Dowdell
contact at stridebird.com
Mon Nov 9 21:38:15 EST 2015
On 10/11/15 08:12, Bernie Lazlo wrote:
> > > import json
> > >import urllib
> > >url ="http://www.wickson.net/geography_assignment.json"
> > >response = urllib.urlopen(url)
> > >data = json.loads(response.read())
All good up to data. Now:
# make a list of scores
scores = [d['score'] for d in data['comments'] if
isinstance(d['score'], int) ]
# analysis
total_scores = sum(scores)
average_score= total_scores/float(len(scores))
min_score, max_score = min(scores), max(scores)
pd
More information about the Python-list
mailing list