<div class="gmail_quote">On Fri, May 13, 2011 at 11:15 AM, noydb <span dir="ltr"><<a href="mailto:jenn.duerr@gmail.com">jenn.duerr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I want some code to take the items in a semi-colon-delimted string<br>
"list" and places each in a python list.  I came up with below.  In<br>
the name of learning how to do things properly, do you experts have a<br>
better way of doing it?<br>
<br>
Thanks for any inputs!<br>
<br>
***<br>
x = "red;blue;green;yellow" ## string of semi-colon delimited colors<br>
<br>
color_list = []<br>
## sc = semi-colon<br>
<br>
while x.find(";") <> -1:<br>
    sc_pos = x.find(";")<br>
    current_color = x[0:sc_pos] ## color w/o sc<br>
    current_color_sc = x[0:sc_pos+1] ## color with sc<br>
    color_list.append(current_color) ## append color to list<br>
    x = x.replace(current_color_sc, "") ## remove color and sc from<br>
string<br>
    print current_color<br>
    print color_list<br>
    print x + "\n"<br>
<br>
color_list.append(x) # append last color left in x (no sc at end of<br>
string)<br>
print color_list<br>
<br>
print "done"<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><div>Try the following:</div><div><br></div><div>    color_list = x.split(";")</div><div><br></div><div>Python string objects have a variety of helpful methods.  Take a look at <a href="http://docs.python.org/library/stdtypes.html#string-methods">http://docs.python.org/library/stdtypes.html#string-methods</a>.  Hope that helps.</div>
<div><br></div><div>-eric</div>