[Tutor] Help needed
christopher.henk at allisontransmission.com
christopher.henk at allisontransmission.com
Wed Jun 17 00:42:04 CEST 2009
> My Original message:
>
> I had previously emailed y'all regarding inverting a message input by
the user of the program backwards. After much
> contemplation on your earlier replies I came up with the code I have
included in this email. The problem I am having
> with this code is that the the first character of the message that is
reversed does not come up. Is there a solution
> to this? For my message that I input I used "take this" to test it, use
the same message when the program prompts you
> to enter the message and run it, you'll see what I mean. Also is there a
way to say reverse the string in a way so the
> reversed string would result to "this take" if you use my example? And
is there a way to stop the loop without the use
> of break? Thanks for the help!
>
As to your second part of your request you can use the function split.
http://www.python.org/doc/2.4.4/lib/string-methods.html
>>> mystring="Mary had a little lamb."
>>> mystring.split()
['Mary', 'had', 'a', 'little', 'lamb.']
>>>
And then you can use slicing to reverse the created list the same way you
did with the full string.
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090616/2442cd7c/attachment.htm>
More information about the Tutor
mailing list