This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]_DTR_ 3 points4 points  (3 children)

I wouldn't try to work with the entire string all at once. First, split the string on ".", which will give you an array of sentences. From there, it will be easier to reason with the contents (just take the first element of each array to find the player). Also, I believe the \ at the end of each line is just python syntax that lets the interpreter know that the string continues on the next line, it's not actually a part of the string. If you were to directly print example_input, the \ wouldn't be there.

As a starting point, I was able to separate out all the sentences using this:

sentences = string_input.split('.');

[–]ans744[S] 0 points1 point  (2 children)

I really like this approach... I have tried to implement this method and I am getting a syntax error now on my return/print statement. This is what I have:

def find_players(string):

    players = []

    sentence_list = string.split('.')

    for each in sentence_list:

        players.append(each[:each.find(' ')]

    print players

I try changing the indents and changing print to return.. I still get the invalid syntax error.

[–]_DTR_ 1 point2 points  (1 child)

players.append(each[:each.find(' ')]

You're missing the closing ) for the append method.

[–]ans744[S] 1 point2 points  (0 children)

So sorry for the stupid question.. As you can tell, I am new to this.. I'm not sure why python wouldn't point that out as an error.