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
Amit Khemka wrote:
> On 8/22/07, james_027 <[EMAIL PROTECTED]> wrote:
>> 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
>> ac
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
On 8/22/07, james_027 <[EMAIL PROTECTED]> wrote:
> 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 insi
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 easy introduction.
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
Thanks
james
--
http://mai
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
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):
24 matches
Mail list logo