0

I'm having difficulties splitting up a string (that I read from a textfile) into three parts in a list (that I will then use in a function).

The issue I'm having is that the 3rd element of the string is not always one word (sometimes its multiple words, but I want them to be counted as ONE)
ex for one line:
1200 90 Class
ex for another line:
1900 120 Date Night

I can get the first instance to work just fine by using split() on my string, but when I try the second instance, I get '1900' , '120', 'Date', 'Night'...when I want it to read '1900', '120', 'Date Night'.

Is there a way to specify the split to be a space for the first two parts of the string and then the third part is everything up until the new line?

Or how how should I go about this?

Thank you

Edited by paraclete: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Gribouillis
1

You can use a second argument to split

>>> "1900 120 Date Night".split(" ", 2)
['1900', '120', 'Date Night']

Otherwise, use a regular expression (the re module).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.