Re: [Tutor] how to print a message backwards

2009-09-25 Thread Lie Ryan
Emile van Sebille wrote: On 9/23/2009 7:22 AM Ali Sina said... #Message backward printer message=input('Enter your message: ') for i in range(len(message),0,-1): print(message) This is the code which I have written. All it does is count the number of letters starting from backwards. The

Re: [Tutor] how to print a message backwards

2009-09-24 Thread Kent Johnson
On Thu, Sep 24, 2009 at 7:02 PM, Sander Sweers wrote: > Now that I know what to look for I went to the online python docs [1] > and tried to find where it has been documented. > > Unfortunately all the slicing examples I found do not even mention that > there is optional step value. See footnote

Re: [Tutor] how to print a message backwards

2009-09-24 Thread Sander Sweers
On Thu, 2009-09-24 at 08:07 -0400, Serdar Tumgoren wrote: > You should find plenty by googling for "python slice step sequence" Now that I know what to look for I went to the online python docs [1] and tried to find where it has been documented. Unfortunately all the slicing examples I found do

Re: [Tutor] how to print a message backwards

2009-09-24 Thread Serdar Tumgoren
> Does anyone have an advanced topic on slicing where the :: notation is > explained? > You should find plenty by googling for "python slice step sequence" Here are a few with links to further resources: http://www.python.org/doc/2.3/whatsnew/section-slices.html http://stackoverflow.com/questions

Re: [Tutor] how to print a message backwards

2009-09-24 Thread Sander Sweers
2009/9/24 ALAN GAULD : >> print message[::-1] > > Yes, the for loop doing one character at a time will be much > slower than using a slice. The slice is more pythonic but less general. > A reverse loop is something that is often needed in programming > solutions so it's useful to know how to do it

Re: [Tutor] how to print a message backwards

2009-09-23 Thread Robert Berman
Thank you for the clear explanation. Robert On Wed, 2009-09-23 at 23:40 +, ALAN GAULD wrote: > > Is there a significant difference in speed, style, or any pythonesque > > reasoning between Alan's solution and > > print message[::-1] > > > Yes, the for loop doing one character at a time

Re: [Tutor] how to print a message backwards

2009-09-23 Thread ALAN GAULD
> Is there a significant difference in speed, style, or any pythonesque > reasoning between Alan's solution and > print message[::-1] Yes, the for loop doing one character at a time will be much slower than using a slice. The slice is more pythonic but less general. A reverse loop is something

Re: [Tutor] how to print a message backwards

2009-09-23 Thread Emile van Sebille
On 9/23/2009 7:22 AM Ali Sina said... #Message backward printer message=input('Enter your message: ') for i in range(len(message),0,-1): print(message) This is the code which I have written. All it does is count the number of letters starting from backwards. The proper code should so some

Re: [Tutor] how to print a message backwards

2009-09-23 Thread Robert Berman
Is there a significant difference in speed, style, or any pythonesque reasoning between Alan's solution and print message[::-1] Thanks for any information, Robert On Wed, 2009-09-23 at 18:51 +0100, Alan Gauld wrote: > "Ali Sina" wrote > > #Message backward printer > message=input('Enter you

Re: [Tutor] how to print a message backwards

2009-09-23 Thread Alan Gauld
"Ali Sina" wrote #Message backward printer message=input('Enter your message: ') for i in range(len(message),0,-1): print(message) This is the code which I have written. All it does is count the number of letters starting from backwards. Correct, plus it prints the original message eac

Re: [Tutor] how to print a message backwards

2009-09-23 Thread Serdar Tumgoren
> http://docs.python.org/tutorial/introduction.html#strings > The below page is a better introduction to sequences: http://effbot.org/zone/python-list.htm It uses lists, but the lessons on slicing also apply to strings (which are a type of sequence). HTH! Serdar

Re: [Tutor] how to print a message backwards

2009-09-23 Thread Serdar Tumgoren
Try reading up on sequences and slicing. They offer a very elegant solution to your (homework?) problem. http://docs.python.org/tutorial/introduction.html#strings ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http

[Tutor] how to print a message backwards

2009-09-23 Thread Ali Sina
#Message backward printer message=input('Enter your message: ') for i in range(len(message),0,-1):     print(message) This is the code which I have written. All it does is count the number of letters starting from backwards. The proper code should so something like this: Enter your message: Hi