It feels so good, so quick and not C!

BB bbondi at pacbell.net
Tue Mar 18 02:49:39 CET 2003


Hi ya'all
  I've been lurking and learning as much as I can. I then decided to do a
simple project to write a "reverse string" routine. This helped a lot! It
showed me that I really think in C terms. I am beginning to see the value of
lists and the simplicity they bring to manipulation of data.
  Anyway, I throwing this piece of code into the arena to be kicked about -
I hope to learn even more this way.

print "This is a prompt. Enter a string to be reversed: ",
sOrig = raw_input()#get a string to work on
sRev=""#init
char_count=len(sOrig)#now I have the string length
while ((char_count - 1) >= 0):#loop thru string backwards, zero based
   char_count = char_count - 1
   sRev = sRev+sOrig[char_count]#create the reverse string
print sRev






More information about the Python-list mailing list