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
> 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
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
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
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
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
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
>
> > 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
; > 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
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
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
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
> > 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
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
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
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
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
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
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
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?
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):
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
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
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
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
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
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
>>
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'),
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
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
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
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
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
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
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
<[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
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
> > 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
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
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__
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
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
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
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
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
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
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
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
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
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
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
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
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
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
[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
>
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
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(
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
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):
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
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
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
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
+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
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
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
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():
>
>
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
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
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
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
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
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
> 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
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
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
i wanted to suggest this myself. +1
-tomer
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
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
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
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/
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
Thank you Mr. Stroud.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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://
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
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:
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
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
>-- 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
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
>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 (
>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 - 100 of 108 matches
Mail list logo