greetings, and welcome to Python!
there were some good solutions using the extended slice operator
([::-1]), but that may be an obscure notation to many newbies to
Python, as powerful as it can be.
i'm going to pick up terry's response and further clarify here (i hope!):
> string_list_orig = str
Christopher Spears wrote:
> my_str = raw_input("Enter a string: ")
>
> string_list = []
>
> for s in my_str:
> string_list.append(s)
This can be written:
string_list = list(my_str)
Kent
___
Tutor maillist - Tutor@python.org
http://mail.pyth
On Fri, Sep 28, 2007 at 04:59:26PM -0700, Christopher Spears wrote:
> How do I get around this? Is there a better way to
> write this script? I can't figure out how to loop
> through a string starting from the last character.
A string is a sequence of chars, and you can use slices with it [1].
Greetings,
Try something with this:
>>> string = 'abc'
>>> string
'abc'
>>> for i in range(len(string)-1,-1,-1):
... print string[i],
...
c b a
--
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/index.html
On 9/28/07, Christopher Spears <[EMAIL PROTECTED]> wrote:
>
On Fri, 28 Sep 2007, Christopher Spears wrote:
> I'm trying to write a script that detects if a string
> is palindromic (same backward as it is forward). This
> is what I have so far:
> my_str = raw_input("Enter a string: ")
> string_list = []
Here you are creating a list and assiging the name
Christopher Spears wrote:
> I'm trying to write a script that detects if a string
> is palindromic (same backward as it is forward). This
> is what I have so far:
>
> #!/usr/bin/env python
>
> my_str = raw_input("Enter a string: ")
>
> string_list = []
>
> for s in my_str:
> string_list.a