Spell a String in reverse

Thread Solved

Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Spell a String in reverse

 
0
  #1
Oct 28th, 2006
What is the most efficient way to spell a string in reverse, for instance s = "banana".
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 128
Reputation: LaMouche is on a distinguished road 
Solved Threads: 19
LaMouche's Avatar
LaMouche LaMouche is offline Offline
Junior Poster

Re: Spell a String in reverse

 
0
  #2
Oct 28th, 2006
This works:

[php]
s = "banana"
s_reversed = s[::-1]
[/php]
It might be helpful to encapsulate it:

[php]
def s_reverse(s):
return s[::-1]

s = "banana"
s_reversed = s_reverse(s)
print s_reversed # ananab

x = "hello"
x_r = s_reverse(x)
print x_r # olleh
[/php]
Last edited by LaMouche; Oct 28th, 2006 at 5:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Spell a String in reverse

 
0
  #3
Oct 29th, 2006
Works great! I have to play around with Python slicing. Thanks LaMouche!
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 128
Reputation: LaMouche is on a distinguished road 
Solved Threads: 19
LaMouche's Avatar
LaMouche LaMouche is offline Offline
Junior Poster

Re: Spell a String in reverse

 
0
  #4
Oct 29th, 2006
No problem. I must say that wasn't my original code. I used the mighty google.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC