On Thu, Dec 17, 2009 at 7:57 PM, Richard D. Moores <[email protected]> wrote:
> def prestrings2list(a_str):
>     word = ""
>     list_of_strings = []
>     length_of_a_string = len(a_str)
>     for i, char in enumerate(a_str):
>         if i == length_of_a_string - 1:
>             word += char
>             word = word.rstrip()
>             list_of_strings.append(word)
>         elif char == ",":
>             word = word.strip()
>             list_of_strings.append(word)
>             word = ""
>         elif char != " ":
>             word += char
>         elif char == " " and word != "" and a_str[i - 1] != " ":
>             word += char
>     return list_of_strings

I think you want
def prestrings2list(a_str):
    return [i.strip() for i in a_str.split(',')]

Kent
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to