Re: conditional for-statement

2009-08-26 Thread seb
On Aug 25, 11:57 pm, Piet van Oostrum wrote: > You can also say: > [x+y for x in range(3) for y in range(4) if x < y] > If you want to write this as a loop you have to put the for's on > separate lines separated by colons, so why not the if also? Or would you > also like to have the for's on one l

Re: conditional for-statement

2009-08-25 Thread Piet van Oostrum
> seb (s) wrote: >s> i am still a bit puzzle by the following. >s> I read in >http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Generators >s> """Python 3.0 unifies all collection types by introducing dict and set >s> comprehensions, similar to list comprehensions: > [ n*n for

Re: conditional for-statement

2009-08-25 Thread seb
On Aug 25, 10:46 pm, Falcolas wrote: > On Aug 25, 1:58 pm, seb wrote: > > > On Aug 25, 9:42 pm, Falcolas wrote: > > > On Aug 25, 11:25 am, seb wrote: > > > So, what part of the statement does the "if" statement belong to; > > > particularly a concern considering this is valid python: > > > > fo

Re: conditional for-statement

2009-08-25 Thread Falcolas
On Aug 25, 1:58 pm, seb wrote: > On Aug 25, 9:42 pm, Falcolas wrote: > > On Aug 25, 11:25 am, seb wrote: > > So, what part of the statement does the "if" statement belong to; > > particularly a concern considering this is valid python: > > > for x in y if y else z: > >     body > > can this be d

Re: conditional for-statement

2009-08-25 Thread seb
On Aug 25, 9:42 pm, Falcolas wrote: > On Aug 25, 11:25 am, seb wrote: > > > > > We could as consistenly explain that the syntax > > > for n in range(10) if n%3==0: > >   body > > > means > > > for n in range(10): > >   if n%3==0: > >     body > > > This syntax has also the benefit of avoiding an

Re: conditional for-statement

2009-08-25 Thread Falcolas
On Aug 25, 11:25 am, seb wrote: > We could as consistenly explain that the syntax > > for n in range(10) if n%3==0: >   body > > means > > for n in range(10): >   if n%3==0: >     body > > This syntax has also the benefit of avoiding an extra level of > indentation (the one for the if) that bears

Re: conditional for-statement

2009-08-25 Thread Rami Chowdhury
We could as consistenly explain that the syntax for n in range(10) if n%3==0: body means for n in range(10): if n%3==0: body This syntax has also the benefit of avoiding an extra level of indentation (the one for the if) that bears no real meaning on a structural level. I'm sorry, I

Re: conditional for-statement

2009-08-25 Thread seb
> > > Indeed, but we could have the same syntax than for generators but > > directly in the for statement as in > > for variable in generator if condition: > >     body > > > Is there a special reason for not doing so ? A rejected PEP ? > > Well, the Zen of P

Re: conditional for-statement

2009-08-25 Thread seb
; >         print i > > >> > it' better readable, and > > >> > for i in range(6,10): > >> >     print i > > >> > it's event better. > > >> How about using a generator expression instead of a list? > > >>   fo

Re: conditional for-statement

2009-08-24 Thread Bruno Desthuilliers
seb a écrit : Hi, i was wondering if there is a syntax alike: for i in range(10) if i > 5: print i equivalent to for i in (for i in range(10) if i>5): print i what about : for i in range(6, 10): print i More seriously: for i in range(10): if i > 5: print i -- h

Re: conditional for-statement

2009-08-23 Thread Mel
seb wrote: > On Aug 23, 6:18 pm, John Posner wrote: [ ... ] >> How about using a generator expression instead of a list? >> >> for i in (x for x in range(10) if x > 5): >> print i >> >> -John > > Indeed, but we could have the same syntax than fo

Re: conditional for-statement

2009-08-23 Thread Chris Rebert
t; >> > for i in range(6,10): >> >     print i >> >> > it's event better. >> >> How about using a generator expression instead of a list? >> >>   for i in (x for x in range(10) if x > 5): >>       print i >> >> -John

Re: conditional for-statement

2009-08-23 Thread seb
> > for i in range(6,10): > > >     print i > > > > it's event better. > > > How about using a generator expression instead of a list? > > >   for i in (x for x in range(10) if x > 5): > >       print i > > > -John > > Ind

Re: conditional for-statement

2009-08-23 Thread seb
or expression instead of a list? > >   for i in (x for x in range(10) if x > 5): >       print i > > -John Indeed, but we could have the same syntax than for generators but directly in the for statement as in for variable in generator if condition: body Is there a special reason for not doing so ? A rejected PEP ? -- http://mail.python.org/mailman/listinfo/python-list

Re: conditional for-statement

2009-08-23 Thread John Posner
Hi, i was wondering if there is a syntax alike: for i in range(10) if i > 5: print i You can write for i in filter(lambda i: i > 5, range(10)): print i but for i in range(10): if i > 5: print i it' better readable, and for i in range(6,10): print i it's e

Re: conditional for-statement

2009-08-23 Thread David
Il Sun, 23 Aug 2009 01:09:04 -0700 (PDT), seb ha scritto: > Hi, > > i was wondering if there is a syntax alike: > > for i in range(10) if i > 5: > print i You can write for i in filter(lambda i: i > 5, range(10)): print i but for i in range(10): if i > 5: print i it' be

Re: conditional for-statement

2009-08-23 Thread Francesco Bochicchio
On Aug 23, 10:09 am, seb wrote: > Hi, > > i was wondering if there is a syntax alike: > > for i in range(10) if i > 5: >     print i > > equivalent to > > for i in (for i in range(10) if i>5): >     print i > > sebastien AFAIK, no syntax fo that. But the standard syntax is not too different: for

Re: conditional for-statement

2009-08-23 Thread Benjamin Peterson
seb gmail.com> writes: > > Hi, > > i was wondering if there is a syntax alike: > > for i in range(10) if i > 5: > print i for i in range(10): if i > 5: print i -- http://mail.python.org/mailman/listinfo/python-list

conditional for-statement

2009-08-23 Thread seb
Hi, i was wondering if there is a syntax alike: for i in range(10) if i > 5: print i equivalent to for i in (for i in range(10) if i>5): print i sebastien -- http://mail.python.org/mailman/listinfo/python-list

Re: Is the Python for statement the same as for each in other languages?

2008-04-08 Thread [EMAIL PROTECTED]
On 8 avr, 19:55, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > jmDesktop schrieb: > > > Thank you. It looks like it is, but I wanted to make sure I > > understood. Also, I didn't see a "regular" for loop construct either > > (i=0;i<=10;i++), etc. I'm still new at it, but is there one of those?

Re: Is the Python for statement the same as for each in other languages?

2008-04-08 Thread Diez B. Roggisch
jmDesktop schrieb: > Thank you. It looks like it is, but I wanted to make sure I > understood. Also, I didn't see a "regular" for loop construct either > (i=0;i<=10;i++), etc. I'm still new at it, but is there one of those? Yes, it's foreach. And for your usecase, use for i in xrange(11):

Is the Python for statement the same as for each in other languages?

2008-04-08 Thread jmDesktop
Thank you. It looks like it is, but I wanted to make sure I understood. Also, I didn't see a "regular" for loop construct either (i=0;i<=10;i++), etc. I'm still new at it, but is there one of those? -- http://mail.python.org/mailman/listinfo/python-list

Re: for statement on empty iterable

2007-08-22 Thread J. Cliff Dyer
Neil Cerutti wrote: On 2007-08-22, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: While it is desireable to not only write working, but also aesthetically pleasing code, as a beginner you shouldn't worry too much. The sense of aesthetics develops with time. Important is to try and grasp the idio

Re: for statement on empty iterable

2007-08-22 Thread Neil Cerutti
On 2007-08-22, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > While it is desireable to not only write working, but also > aesthetically pleasing code, as a beginner you shouldn't worry > too much. The sense of aesthetics develops with time. Important > is to try and grasp the idioms of the language

Re: for statement on empty iterable

2007-08-22 Thread Steve Holden
your quick answer ... Actually I was thinking how do I >> access the index inside a for statement? Can you help > > Have a look at "enumerate", You can iterate over a list like: > > for i,x in enumerate(['a', 'b', 'c']): > pri

Re: for statement on empty iterable

2007-08-22 Thread Eric Abrahamsen
Here's another simple method: l = ['j', 'a', 'm', 'e', 's'] counter = 0 for i in l: # Do your code counter += 1 print counter Yrs, Eric > l = ['j', 'a', 'm', 'e', 's'] > > for i in l > # i want to know the nth number of times it has loop thru or > something like counter? > > Thanks

Re: for statement on empty iterable

2007-08-22 Thread Diez B. Roggisch
james_027 schrieb: > hi, > >> Oh I see. You have to combine a couple of concepts but for this >> example you'd say: >> >>name = 'james' # 'l' looks too much like the digit 1 >>for i,c in enumerate(name): >> print i, c >>print i >> >> enumerate(name) generates the sequence >>

Re: for statement on empty iterable

2007-08-21 Thread james_027
hi, > Oh I see. You have to combine a couple of concepts but for this > example you'd say: > >name = 'james' # 'l' looks too much like the digit 1 >for i,c in enumerate(name): > print i, c >print i > > enumerate(name) generates the sequence > >(0,'j'), (1,'a'), (2,'m'),

Re: for statement on empty iterable

2007-08-21 Thread Paul Rubin
james_027 <[EMAIL PROTECTED]> writes: > Yes i am new to python :). I am sorry I should be clarify myself ... > for example > > l = ['j', 'a', 'm', 'e', 's'] > > for i in l > # i want to know the nth number of times it has loop thru or > something like counter? Oh I see. You have to combine a c

Re: for statement on empty iterable

2007-08-21 Thread Amit Khemka
lly I was thinking how do I > access the index inside a for statement? Can you help Have a look at "enumerate", You can iterate over a list like: for i,x in enumerate(['a', 'b', 'c']): print i, x It prints: 0 a 1 b 2 c cheers, amit Amit Khemka

Re: for statement on empty iterable

2007-08-21 Thread james_027
hi, > It sounds like you're just starting to learn the language... have you > read the online tutorial yet? That is a pretty easy introduction. > > See:http://python.org/doc/ > > Anyway, you can say > >for i in (1,2,3): > print i*5 > > to print 5, 10, and 15 on separate lines, for examp

Re: for statement on empty iterable

2007-08-21 Thread Paul Rubin
james_027 <[EMAIL PROTECTED]> writes: > Thanks for your quick answer ... Actually I was thinking how do I > access the index inside a for statement? Can you help It sounds like you're just starting to learn the language... have you read the online tutorial yet? That is a pretty

Re: for statement on empty iterable

2007-08-21 Thread james_027
hi Paul, > > That doesn't crash or anything like that, but it also doesn't > set the index variable, which can cause confusion in some situations. Thanks for your quick answer ... Actually I was thinking how do I access the index inside a for statement? Can you help Than

Re: for statement on empty iterable

2007-08-21 Thread Paul Rubin
james_027 <[EMAIL PROTECTED]> writes: > for i in []: > #do something > is this safe? or should I put a if statement to test it first? That doesn't crash or anything like that, but it also doesn't set the index variable, which can cause confusion in some situations. -- http://mail.python.org/mail

for statement on empty iterable

2007-08-21 Thread james_027
hi, I need to do some for loop on iterables which could be empty sometimes, for example a_list = [] for i in a_list: #do something is this safe? or should I put a if statement to test it first? Thanks james -- http://mail.python.org/mailman/listinfo/python-list

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

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: 8

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 u

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 u

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 dicti

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

Re: FOR statement

2006-10-21 Thread Theerasak Photha
On 10/21/06, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > Theerasak Photha schrieb: > > On 21 Oct 2006 00:50:34 -0700, Ant <[EMAIL PROTECTED]> wrote: > > > >> But there's a good reason not to. Try: > >> > >> printreverse(range(1000)) > >> > >> Recursion has a maximum depth (of 1000 by default) in

Re: FOR statement

2006-10-21 Thread Diez B. Roggisch
Theerasak Photha schrieb: > On 21 Oct 2006 00:50:34 -0700, Ant <[EMAIL PROTECTED]> wrote: > >> But there's a good reason not to. Try: >> >> printreverse(range(1000)) >> >> Recursion has a maximum depth (of 1000 by default) in Python. > > I guess Python isn't tail-recursive then? To complement my

Re: FOR statement

2006-10-21 Thread Diez B. Roggisch
Theerasak Photha schrieb: > On 21 Oct 2006 00:50:34 -0700, Ant <[EMAIL PROTECTED]> wrote: > >> But there's a good reason not to. Try: >> >> printreverse(range(1000)) >> >> Recursion has a maximum depth (of 1000 by default) in Python. > > I guess Python isn't tail-recursive then? Nope. And given

Re: FOR statement

2006-10-21 Thread Theerasak Photha
On 21 Oct 2006 01:31:55 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Theerasak Photha: > > I guess Python isn't tail-recursive then? > > Right. > > > > Well, algorithms seem to be more naturally expressed iteratively in > > Python, and to be fair, most uses of recursion you see in e.g., Sc

Re: FOR statement

2006-10-21 Thread bearophileHUGS
Theerasak Photha: > I guess Python isn't tail-recursive then? Right. > Well, algorithms seem to be more naturally expressed iteratively in > Python, and to be fair, most uses of recursion you see in e.g., Scheme > textbooks are really just grandstanding in the real world. Still, some algorithms

Re: FOR statement

2006-10-21 Thread Theerasak Photha
On 21 Oct 2006 00:50:34 -0700, Ant <[EMAIL PROTECTED]> wrote: > But there's a good reason not to. Try: > > printreverse(range(1000)) > > Recursion has a maximum depth (of 1000 by default) in Python. I guess Python isn't tail-recursive then? Well, algorithms seem to be more naturally expressed it

Re: FOR statement

2006-10-21 Thread Ant
Jordan Greenberg wrote: ... > >>> def printreverse(lst): > if lst: > printreverse(lst[1:]) > print lst[:1][0] Convoluted way of writing "print lst[0]" ! > >>> printreverse([1,2,3,4]) > > No good reason at all to do it this way. But recursion is fun. But there's

Re: FOR statement

2006-10-21 Thread Lad
[EMAIL PROTECTED] wrote: > Lad wrote: > > If I have a list > > > > Mylist=[1,2,3,4,5] > > I can print it > > > > for i in Mylist: > >print i > > > > and results is > > 1 > > 2 > > 3 > > 4 > > 5 > > > > > > But how can I print it in a reverse order so that I get > > 5 > > 4 > > 3 > > 2 > > 1 >

Re: FOR statement

2006-10-20 Thread Jordan Greenberg
Lad wrote: > If I have a list > > Mylist=[1,2,3,4,5] > I can print it > > for i in Mylist: >print i > > and results is > 1 > 2 > 3 > 4 > 5 > > > But how can I print it in a reverse order so that I get > 5 > 4 > 3 > 2 > 1 >>> def printreverse(lst): if lst: printrev

Re: FOR statement

2006-10-20 Thread Grant Edwards
On 2006-10-20, Lad <[EMAIL PROTECTED]> wrote: > If I have a list > > Mylist=[1,2,3,4,5] [...] > But how can I print it in a reverse order so that I get > 5 > 4 > 3 > 2 > 1 Another option: >>> Mylist=[1,2,3,4,5] >>> for i in Mylist[::-1]: ... print i ... 5 4 3 2 1 But, I think the reversed(

Re: FOR statement

2006-10-20 Thread [EMAIL PROTECTED]
Lad wrote: > If I have a list > > Mylist=[1,2,3,4,5] > I can print it > > for i in Mylist: >print i > > and results is > 1 > 2 > 3 > 4 > 5 > > > But how can I print it in a reverse order so that I get > 5 > 4 > 3 > 2 > 1 > > > > ? > > > Thanks. > L reverse the list in place with reverse meth

Re: FOR statement

2006-10-20 Thread Christophe
Lad a écrit : > If I have a list > > Mylist=[1,2,3,4,5] > I can print it > > for i in Mylist: >print i > > and results is > 1 > 2 > 3 > 4 > 5 > > > But how can I print it in a reverse order so that I get > 5 > 4 > 3 > 2 > 1 > > > > ? > > > Thanks. > L > for i in reversed(Mylist):

FOR statement

2006-10-20 Thread Lad
If I have a list Mylist=[1,2,3,4,5] I can print it for i in Mylist: print i and results is 1 2 3 4 5 But how can I print it in a reverse order so that I get 5 4 3 2 1 ? Thanks. L -- http://mail.python.org/mailman/listinfo/python-list

RE: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-24 Thread Delaney, Timothy (Tim)
Heiko Wundram wrote: > Am Mittwoch 24 Mai 2006 06:12 schrieb Tim Roberts: >> At one time, it was said that the "%" operator was the fastest way to >> concatenate strings, because it was implemented in C, whereas the + >> operator was interpreted. However, as I recall, the difference was >> hardly

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-23 Thread Heiko Wundram
Am Mittwoch 24 Mai 2006 06:12 schrieb Tim Roberts: > At one time, it was said that the "%" operator was the fastest way to > concatenate strings, because it was implemented in C, whereas the + > operator was interpreted. However, as I recall, the difference was hardly > measurable, and may not eve

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-23 Thread Tim Roberts
Edward Elliott <[EMAIL PROTECTED]> wrote: >bruno at modulix wrote: > >> Edward Elliott wrote: >>> You mean like this: >>> >>> s = "foo" + "bar" >>> s = 'foo' + 'bar' >>> s = 'foo' 'bar' >>> s = '%s%s' % ('foo', 'bar') >[snip] >> The real mantra is actually : >> "There should be one-- and preferab

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-22 Thread Russell E. Owen
+1 It does seem like a natural unificiation of the language -- one less exception to learn. -- Russell -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-22 Thread Edward Elliott
bruno at modulix wrote: > Edward Elliott wrote: >> You mean like this: >> >> s = "foo" + "bar" >> s = 'foo' + 'bar' >> s = 'foo' 'bar' >> s = '%s%s' % ('foo', 'bar') [snip] > The real mantra is actually : > "There should be one-- and preferably only one --obvious way to do it" > > Please note th

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-22 Thread Heiko Wundram
Am Montag 22 Mai 2006 11:27 schrieb Boris Borcic: > Mhhh, your unsugared form remind me of darks hours with primitive BASICS in > my youth - the kind Dijsktra commented on. Why don't you write > > for node in tree: > if node.haschildren(): > As I've replied on

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-22 Thread Boris Borcic
Heiko Wundram wrote: ... > As I've noticed that I find myself typing the latter quite often > in code I write, it would only be sensible to add the corresponding > syntax for the for statement: > > for node in tree if node.haschildren(): > >

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-22 Thread bruno at modulix
Edward Elliott wrote: > George Sakkis wrote: > > >>Em Dom, 2006-05-21 às 17:11 +0200, Heiko Wundram escreveu: >> >>>for node in tree if node.haschildren(): >>> >>> >>>as syntactic sugar for: >>> >>>for node in tree: >>>if not node.haschildren(): >>>continue >>> > > [snip] > >>2) "There should b

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Carl Banks
Edward Elliott wrote: > Special cases aren't special enough to break the rules. (proposal eliminates > the current special case for comprehensions/generators) It really isn't a special case, though. It might seem like it is, but it's not at all when you remember the rules of equivalence between l

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Carl Banks
Heiko Wundram wrote: > The following PEP tries to make the case for a slight unification of for > statement and list comprehension syntax. -1 Adds complexity to the language and saves you nothing but an indent level. However, I encourage you to submit this PEP and get a (almost cer

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Edward Elliott
George Sakkis wrote: > Em Dom, 2006-05-21 às 17:11 +0200, Heiko Wundram escreveu: >> for node in tree if node.haschildren(): >> >> >> as syntactic sugar for: >> >> for node in tree: >> if not node.haschildren(): >> continue >> [snip] > > 2) "There should be one and preferably only one way to d

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread George Sakkis
Felipe Almeida Lessa wrote: > Em Dom, 2006-05-21 às 11:52 -0700, gangesmaster escreveu: > > > Today you can archive the same effect (but not necessarily with the same > > > performance) with: > > > > > > for node in (x for x in tree if x.haschildren()): > > > > > > > true, but it has differen

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Felipe Almeida Lessa
Em Dom, 2006-05-21 às 11:52 -0700, gangesmaster escreveu: > > Today you can archive the same effect (but not necessarily with the same > > performance) with: > > > > for node in (x for x in tree if x.haschildren()): > > > > true, but it has different semantic meanings > I know, that's also

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread gangesmaster
> Today you can archive the same effect (but not necessarily with the same > performance) with: > > for node in (x for x in tree if x.haschildren()): > true, but it has different semantic meanings -tomer -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Felipe Almeida Lessa
Em Dom, 2006-05-21 às 17:11 +0200, Heiko Wundram escreveu: > for node in tree if node.haschildren(): > > > as syntactic sugar for: > > for node in tree: > if not node.haschildren(): > continue > Today you can archive the same effect

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread KW
On 2006-05-21, Heiko Wundram wrote: > Hi all! > > The following PEP tries to make the case for a slight unification of for > statement and list comprehension syntax. Sounds great! -- Konrad -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread gangesmaster
i wanted to suggest this myself. +1 -tomer -- http://mail.python.org/mailman/listinfo/python-list

PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Heiko Wundram
Hi all! The following PEP tries to make the case for a slight unification of for statement and list comprehension syntax. Comments appreciated, including on the sample implementation. === PEP: xxx Title: Unification of for-statement and list-comprehension syntax Version: $Revision$ Last

Re: Multiple tuples for one for statement

2005-04-25 Thread Ivan Van Laningham
Peter Hansen wrote: > > Ivan Van Laningham wrote: > > I can see that now. I had three hours sleep last night and my brain > > hurts, so I don't get it. I seek enlightenment. > > So do I: did you mean you don't even "get" what > my code is doing...? Yes. I barely remember my own name right n

Re: Multiple tuples for one for statement

2005-04-25 Thread Peter Hansen
Ivan Van Laningham wrote: I can see that now. I had three hours sleep last night and my brain hurts, so I don't get it. I seek enlightenment. So do I: did you mean you don't even "get" what my code is doing, or you don't get what the OP really wanted, or something else? (My sample works only beca

Re: Multiple tuples for one for statement

2005-04-25 Thread Ivan Van Laningham
Hi All-- Peter Hansen wrote: > > > Define "works": > > >>> a = (1,2,3) > >>> b = ('a','b','c') > >>> c = (None, 'foo', 3.14) > >>> tup1 = (1,2,3) > >>> tup2 = ('a','b','c') > >>> tup3 = (None, 'foo', 3.14) > >>> for a,b,c in (tup1,tup2,tup3): > ... print a > ... print b > ... print

Re: Multiple tuples for one for statement

2005-04-25 Thread Peter Hansen
Ivan Van Laningham wrote: "R. C. James Harlow" wrote: On Monday 25 April 2005 14:34, Ivan Van Laningham wrote: "R. C. James Harlow" wrote: or just: for a,b,c in (tup1, tup2, tup3): print a print b print c And this works in Python version??? Ah, reading the replies to the original post, thi

Re: Multiple tuples for one for statement

2005-04-25 Thread Ivan Van Laningham
Hi All-- "R. C. James Harlow" wrote: > > On Monday 25 April 2005 14:34, Ivan Van Laningham wrote: > > Hi All-- > > > > "R. C. James Harlow" wrote: > > > or just: > > > > > > for a,b,c in (tup1, tup2, tup3): > > > print a > > > print b > > > print c > > > > And this works in Python ver

Re: Multiple tuples for one for statement

2005-04-25 Thread R. C. James Harlow
On Monday 25 April 2005 14:34, Ivan Van Laningham wrote: > Hi All-- > > "R. C. James Harlow" wrote: > > or just: > > > > for a,b,c in (tup1, tup2, tup3): > > print a > > print b > > print c > > And this works in Python version??? Ah, reading the replies to the original post, this works

Re: Multiple tuples for one for statement

2005-04-25 Thread Ivan Van Laningham
Hi All-- "R. C. James Harlow" wrote: > > or just: > > for a,b,c in (tup1, tup2, tup3): > print a > print b > print c > And this works in Python version??? Metta, Ivan -- Ivan Van Laningham God N Locomotive Works http://www.andi-holmes.co

Re: Multiple tuples for one for statement

2005-04-25 Thread R. C. James Harlow
On Monday 25 April 2005 04:20, James Stroud wrote: > for a,b,c in zip(tup1, tup2, tup3): >print a >print b >print c or just: for a,b,c in (tup1, tup2, tup3): print a print b print c pgpJ0RNTnCUA3.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/

Re: Multiple tuples for one for statement

2005-04-24 Thread Daniel Cer
Harlin Seritt wrote: I have three tuples of the same size: tup1, tup2, tup3 I'd like to do something like this: for a,b,c in tup1, tup2, tup3: print a print b print c Of course, you get an error when you try to run the pseudocode above. What is the correct way to get this done? For somethi

Re: Multiple tuples for one for statement

2005-04-24 Thread Harlin Seritt
Thank you Mr. Stroud. -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiple tuples for one for statement

2005-04-24 Thread Kent Johnson
Harlin Seritt wrote: I have three tuples of the same size: tup1, tup2, tup3 I'd like to do something like this: for a,b,c in tup1, tup2, tup3: print a print b print c Presuming that you want a,b,c to be corresponding entries from the three tuples, then zip() is your friend: for a,b,c in z

Re: Multiple tuples for one for statement

2005-04-24 Thread Steven Bethard
Harlin Seritt wrote: I have three tuples of the same size: tup1, tup2, tup3 I'd like to do something like this: for a,b,c in tup1, tup2, tup3: print a print b print c Of course, you get an error when you try to run the pseudocode above. What is the correct way to get this done? for a, b, c

Re: Multiple tuples for one for statement

2005-04-24 Thread James Stroud
for a,b,c in zip(tup1, tup2, tup3): print a print b print c -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list

Multiple tuples for one for statement

2005-04-24 Thread Harlin Seritt
I have three tuples of the same size: tup1, tup2, tup3 I'd like to do something like this: for a,b,c in tup1, tup2, tup3: print a print b print c Of course, you get an error when you try to run the pseudocode above. What is the correct way to get this done? Thanks, Harlin -- http://

Re: Python 2.4 | 7.3 The for statement

2005-03-25 Thread Bengt Richter
On 25 Mar 2005 15:41:25 -0800, "brainsucker" <[EMAIL PROTECTED]> wrote: >Franciso, some more code. > >Breaking with two conditions, and fun with exceptions: > >moflo = 1 >try: > for item1 in range(10): >if (item1 * moflo) == 3: raise StopIteration >for item2 in range(10): > if (item2

Re: Python 2.4 | 7.3 The for statement

2005-03-25 Thread brainsucker
Franciso, some more code. Breaking with two conditions, and fun with exceptions: moflo = 1 try: for item1 in range(10): if (item1 * moflo) == 3: raise StopIteration for item2 in range(10): if (item2 * moflo) == 2: raise StopIteration print "Let's see" except StopIteration:

Re: Python 2.4 | 7.3 The for statement

2005-03-25 Thread brainsucker
As you know is not functional... It represents something that happens everyday on Python programming. We can reduce the other examples of code to: prinf foo Too. :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 2.4 | 7.3 The for statement

2005-03-25 Thread brainsucker
Well facundo, I knew that you were going for the return inside the loop. The exception is cool, but not for newcomers. My proposend code is simpler clearer and more compact, I keep watching your code, and don't know Funcs for breaking loops, exceptions for breaking loops. :o -- http://mail.p

Re: Python 2.4 | 7.3 The for statement

2005-03-25 Thread Ron_Adam
>-- Your code >foo = 0 >for item1 in range(10): > for item2 in range(10): >foo = item1 + item2 >if foo == 2: > print "Let's see" > break # let's go > if (item1 + item2) == 2: >break # one more time >print foo The outer loop never reaches 1, so we can get rid of it along wi

Re: Python 2.4 | 7.3 The for statement

2005-03-25 Thread Facundo Batista
On 24 Mar 2005 19:49:38 -0800, brainsucker <[EMAIL PROTECTED]> wrote: > foo = 0 > for item1 in range(10) until foo == 2: > for item2 in range(10) until foo == 2: > foo = item1 + item2 > if foo == 2: print "Let's see" > print foo In this case, I'll use the following: try: for item1

Re: Python 2.4 | 7.3 The for statement

2005-03-24 Thread brainsucker
>And that could be modified even further, using current >(unextended) Python... Nice code Wulfraed (or Dennis), back to the basics: -- Your code foo = 0 for item1 in range(10): for item2 in range(10): foo = item1 + item2 if foo == 2: print "Let's see" break # let's go if (

Re: Python 2.4 | 7.3 The for statement

2005-03-22 Thread brainsucker
>Still, this can be acomplished with the break statement, in a more >clear way, with less variables (which implies less work for the gc and >everybody). Glad to read from you Francisco. :) Keep up that hard work, thanks. I have been talking with those Python programmers (And Role players), :) and

  1   2   >