Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98573

Re: Extracting and summing student scores from a JSON file using Python 2.7.10

Newsgroups comp.lang.python
Date 2015-11-09 19:53 -0800
References <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> <n1ro2l$n3t$1@dont-email.me>
Message-ID <9a9e1664-7b36-473d-bebf-3de7c7d13b94@googlegroups.com> (permalink)
Subject Re: Extracting and summing student scores from a JSON file using Python 2.7.10
From wayne.wickson@gmail.com

Show all headers | View raw


On Monday, 9 November 2015 22:27:40 UTC-5, Denis McMahon  wrote:
> On Mon, 09 Nov 2015 15:52:45 -0800, Bernie Lazlo wrote:
> 
> > This should be a simple problem but I have wasted hours on it. Any help
> > would be appreciated. [I have taken my code back to almost the very
> > beginning.]
> > ========================
> > The student scores need to be summed.
> > ========================
> > import json import urllib url =
> > "http://www.wickson.net/geography_assignment.json"
> > response = urllib.urlopen(url)
> > data = json.loads(response.read())
> > lst1 = list(data.items())
> > print lst1
> 
> I find that pprint.pprint is useful for looking at data structures.
> 
> Having looked at the data, and then using appropriate substitutions for 
> <something> and <keyval> in the following:
> 
> sumscore = 0
> students = 0
> 
> for dic in <something>:
>     sumscore = sumscore + dic[<keyval>]
>     students += 1
> 
> print 'Sum of', students, 'scores is', sumscore
> print 'Average of', students, 'scores is', sumscore / students
> 
> It was trivial to generate:
> 
> Sum of 50 scores is 3028
> Average of 50 scores is 60
> 
> -- 
> Denis McMahon
=========================================
Thanks for the reply, Denis. I hope this comes as easily to me some day. :-)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Extracting and summing student scores from a JSON file using Python 2.7.10 Bernie Lazlo <bjlazlo@gmail.com> - 2015-11-09 15:52 -0800
  Re: Extracting and summing student scores from a JSON file using Python 2.7.10 MRAB <python@mrabarnett.plus.com> - 2015-11-10 00:29 +0000
    Re: Extracting and summing student scores from a JSON file using Python 2.7.10 Bernie Lazlo <bjlazlo@gmail.com> - 2015-11-09 17:12 -0800
      Re: Extracting and summing student scores from a JSON file using Python 2.7.10 MRAB <python@mrabarnett.plus.com> - 2015-11-10 01:31 +0000
        Re: Extracting and summing student scores from a JSON file using Python 2.7.10 Bernie Lazlo <bjlazlo@gmail.com> - 2015-11-09 17:53 -0800
          Re: Extracting and summing student scores from a JSON file using Python 2.7.10 MRAB <python@mrabarnett.plus.com> - 2015-11-10 02:13 +0000
      Re: Extracting and summing student scores from a JSON file using Python 2.7.10 Pete Dowdell <contact@stridebird.com> - 2015-11-10 09:38 +0700
  Re: Extracting and summing student scores from a JSON file using Python 2.7.10 Bernie Lazlo <bjlazlo@gmail.com> - 2015-11-09 19:21 -0800
  Re: Extracting and summing student scores from a JSON file using Python 2.7.10 Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-10 03:25 +0000
    Re: Extracting and summing student scores from a JSON file using Python 2.7.10 wayne.wickson@gmail.com - 2015-11-09 19:53 -0800
      Re: Extracting and summing student scores from a JSON file using Python 2.7.10 Bernie Lazlo <bjlazlo@gmail.com> - 2015-11-10 04:14 -0800
  Re: Extracting and summing student scores from a JSON file using Python 2.7.10 Bernie Lazlo <bjlazlo@gmail.com> - 2015-11-10 04:16 -0800

csiph-web