Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43014
| Path | csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian@feete.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'syntax': 0.04; 'newbie': 0.05; 'output': 0.05; 'nested': 0.07; 'squares': 0.07; 'subject:question': 0.10; 'python': 0.11; 'from:addr:ian': 0.16; 'invoking': 0.16; 'received:208.97.132.81': 0.16; 'subject:python.': 0.16; 'xrange': 0.16; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'import': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'math': 0.24; 'header:In-Reply- To:1': 0.27; 'is?': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; '>>>>': 0.31; 'received:208.97': 0.31; 'received:208.97.132': 0.31; 'received:dreamhost.com': 0.31; 'received:g.dreamhost.com': 0.31; "can't": 0.35; 'version': 0.36; 'error.': 0.37; 'example,': 0.37; 'received:10': 0.37; 'to:addr :python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'read': 0.60; 'ian': 0.60; 'most': 0.60; 'numbers': 0.61; 'received:208': 0.61; 'simple': 0.61; 'sum': 0.64; 'more': 0.64; 'here': 0.66; 'subject:. ': 0.67; '165': 0.84; 'subject:Very': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed; d=feete.org; h=message-id :date:from:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; s=feete.org; bh=RLHOqsC c2L7cihuydhc9zJgn6Qs=; b=HxHCZTwvycv6nNklvjucl9G53MgMmbdOVhfvr8j HkkB8hzzxQdt1ps94gcCur6ObootupyKHEXb76cUqraAkXFuO6ES10I2PnoA00x3 MNx72B7YwuNU4yJtVxlrw0vCmuLbd8KCLW813yq8q7ZzuCoDhkMbW8GTzSEQIaPw BbvQ= |
| Date | Sun, 07 Apr 2013 20:23:49 +0100 |
| From | Ian Foote <ian@feete.org> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Newbie to python. Very newbie question |
| References | <f0759987-4ff8-49a1-a826-4ae3f6508030@5g2000yqz.googlegroups.com> <alg3m81dohei58jefi5nmaumcdcvkma2pu@invalid.netcom.com> |
| In-Reply-To | <alg3m81dohei58jefi5nmaumcdcvkma2pu@invalid.netcom.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.252.1365362646.3114.python-list@python.org> (permalink) |
| Lines | 43 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1365362646 news.xs4all.nl 6929 [2001:888:2000:d::a6]:56556 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:43014 |
Show key headers only | View raw
On 07/04/13 20:09, Dennis Lee Bieber wrote: > On Sun, 7 Apr 2013 04:16:27 -0700 (PDT), ReviewBoard User > <lalitha.viswanath@gmail.com> declaimed the following in > gmane.comp.python.general: > >> Hi >> I am a newbie to python and am trying to write a program that does a >> sum of squares of numbers whose squares are odd. >> For example, for x from 1 to 100, it generates 165 as an output (sum >> of 1,9,25,49,81) >> >> 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)) >> >> I am getting a syntax error. >> Can you let me know what the error is? >> > I can't even read that mess... three nested lambda? > > Not the most efficient version but... > >>>> sum( x*x for x in range(100/2) if (x*x % 2) and (x*x < 100) ) > 165 >> > > The range(100/2) is a simple reduction to avoid invoking a sqrt > function... the more economical is > >>>> import math >>>> sum( x*x for x in range(int(math.sqrt(100))) if x*x % 2) > 165 >>>> I'm surprised no one has suggested: >>> import math >>> sum( x*x for x in range(1, int(math.sqrt(100)), 2)) Regards, Ian F
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