more questions...(strings)
sik0fewl
xxdigitalhellxx at hotmail.com
Mon Feb 24 10:17:22 EST 2003
p.s wrote:
> Hi again,
> I've gotten some practice reading strings from files, and using raw_input,
> and now I'm looking into splitting strings.
> I know how to get something like "hello at there", split by doing
> str.split("@"), and I get a list of ["hello", "there"].
> However, I'm trying to get two lists, the first with the string before the
> "@", and the second list with the remainder of the string.
>
> So if i read from a file with:
> one at two
> white at black
> left at right
> I'd end up with this:
> list_one = ["one", "white", "left"]
> list_two = ["two", "black", "right"]
>
> thanks for reading.
> -p-
<read file into list lines>
line_one = []
line_two = []
for line in lines:
temp = string.split (line, '@')
list_one.append (temp[0])
list_two.append (temp[1])
--
Hope this helps,
Ryan
More information about the Python-list
mailing list