Re: NEWBIE: Extending a For Statement.

2007-05-22 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >mosscliffe: >> if key in xrange (60,69) or key == 3: >I keep seeing again and again code like this, mostly from people not >much expert of Python, but the PEP 260 shows the fast in was removed, >so it's O(n). If you're going to point that out, you should at least also

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread Dustan
On May 21, 9:21 am, mosscliffe <[EMAIL PROTECTED]> wrote: > On 21 May, 15:02, [EMAIL PROTECTED] wrote: > > > mosscliffe: > > > > if key in xrange (60,69) or key == 3: > > > I keep seeing again and again code like this, mostly from people not > > much expert of Python, but the PEP 260 shows the fast

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread Eduardo \"EdCrypt\" O. Padoan
> > Perhaps you meant that second one to be: > > (key, mydict[key] for key in mydict if key in xrange(60, 69) or key == > > 3) > > > Clearly not! Its called *list*-comprehension, not tuple-comprehension. ;) With () instead of [], it is a generator expression. http://docs.python.org/ref/genexpr.html

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread Wildemar Wildenburger
Dustan wrote: (key, mydict[key] for key in mydict if key in xrange(60, 69) or key == 3] > File "", line 1 > (key, mydict[key] for key in mydict if key in xrange(60, 69) or > key == 3] > ^ > SyntaxError: invalid syntax > > Perhaps you meant that secon

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread mosscliffe
On 21 May, 15:02, [EMAIL PROTECTED] wrote: > mosscliffe: > > > if key in xrange (60,69) or key == 3: > > I keep seeing again and again code like this, mostly from people not > much expert of Python, but the PEP 260 shows the fast in was removed, > so it's O(n). Maybe removing the fast __contains__

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread mosscliffe
On 21 May, 14:13, Larry Bates <[EMAIL PROTECTED]> wrote: > mosscliffe wrote: > > I keep seeing examples of statements where it seems conditionals are > > appended to a for statement, but I do not understand them. > > > I would like to use one in the following scenario. > > > I have a dictionary of

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread bearophileHUGS
mosscliffe: > if key in xrange (60,69) or key == 3: I keep seeing again and again code like this, mostly from people not much expert of Python, but the PEP 260 shows the fast in was removed, so it's O(n). Maybe removing the fast __contains__ was bad for necomers (or just the casual Python users, t

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread Larry Bates
mosscliffe wrote: > I keep seeing examples of statements where it seems conditionals are > appended to a for statement, but I do not understand them. > > I would like to use one in the following scenario. > > I have a dictionary of > > mydict = { 1: 500, 2:700, 3: 800, 60: 456, 62: 543, 58: 6789

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread Dustan
On May 21, 7:22 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On 21 May 2007 05:10:46 -0700, mosscliffe <[EMAIL PROTECTED]> wrote: > > > > >I keep seeing examples of statements where it seems conditionals are > >appended to a for statement, but I do not understand them. > > >I would like to

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread Dustan
On May 21, 7:22 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On 21 May 2007 05:10:46 -0700, mosscliffe <[EMAIL PROTECTED]> wrote: > > > > >I keep seeing examples of statements where it seems conditionals are > >appended to a for statement, but I do not understand them. > > >I would like to

Re: NEWBIE: Extending a For Statement.

2007-05-21 Thread Jean-Paul Calderone
On 21 May 2007 05:10:46 -0700, mosscliffe <[EMAIL PROTECTED]> wrote: >I keep seeing examples of statements where it seems conditionals are >appended to a for statement, but I do not understand them. > >I would like to use one in the following scenario. > >I have a dictionary of > >mydict = { 1: 500

NEWBIE: Extending a For Statement.

2007-05-21 Thread mosscliffe
I keep seeing examples of statements where it seems conditionals are appended to a for statement, but I do not understand them. I would like to use one in the following scenario. I have a dictionary of mydict = { 1: 500, 2:700, 3: 800, 60: 456, 62: 543, 58: 6789} for key in mydict: if key