[Tutor] how to print a message backwards

Robert Berman bermanrl at cfl.rr.com
Thu Sep 24 04:09:50 CEST 2009


Thank  you  for the clear explanation.

Robert


On Wed, 2009-09-23 at 23:40 +0000, 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 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 for the general case. 
> But where the data  can be sliced that will be faster and more 
> concise.
> 
> Alan G.



More information about the Tutor mailing list