Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43006
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-04-07 10:04 -0700 |
| References | <f0759987-4ff8-49a1-a826-4ae3f6508030@5g2000yqz.googlegroups.com> |
| Message-ID | <8cf004b8-fa76-4c94-b366-fccbf448c914@googlegroups.com> (permalink) |
| Subject | Re: Newbie to python. Very newbie question |
| From | Miki Tebeka <miki.tebeka@gmail.com> |
> I am a newbie to python
Welcome! I hope you'll do great things with Python.
> and am trying to write a program that does a
> sum of squares of numbers whose squares are odd.
OK.
> For example, for x from 1 to 100, it generates 165 as an output (sum
> of 1,9,25,49,81)
I don't follow, you seem to be missing a lot of numbers. For example 3^2 = 9 which is odd as well.
> Here is the code I have
> print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x:
> x*x, xrange
> (10**6)))) = sum(x*x for x in xrange(1, 10**6, 2))
print X = Y is a syntax error. Why do you need the 2'nd part.
In general, we're moving to list/generator comperhension over map/filter.
Something like:
print(sum(x*x for x in xrange(10**6) if (x*x)%2))
HTH,
Miki
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Newbie to python. Very newbie question ReviewBoard User <lalitha.viswanath@gmail.com> - 2013-04-07 04:16 -0700
Re: Newbie to python. Very newbie question Kruno Saho <kruno.saho@gmail.com> - 2013-04-07 04:19 -0700
Re: Newbie to python. Very newbie question Dave Angel <davea@davea.name> - 2013-04-07 07:50 -0400
Re: Newbie to python. Very newbie question rusi <rustompmody@gmail.com> - 2013-04-07 10:02 -0700
Re: Newbie to python. Very newbie question Miki Tebeka <miki.tebeka@gmail.com> - 2013-04-07 10:04 -0700
Re: Newbie to python. Very newbie question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-07 15:09 -0400
Re: Newbie to python. Very newbie question Miki Tebeka <miki.tebeka@gmail.com> - 2013-04-07 16:57 -0700
Re: Newbie to python. Very newbie question Ian Foote <ian@feete.org> - 2013-04-07 20:23 +0100
Re: Newbie to python. Very newbie question Arnaud Delobelle <arnodel@gmail.com> - 2013-04-07 21:16 +0100
Re: Newbie to python. Very newbie question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-08 03:16 +0000
csiph-web