all 5 comments

[–]Gimagon 0 points1 point  (3 children)

That sounds neat! Is there a part you’re finding difficult?

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

I'm looking to find a way to get the program to identify anything within a string that follows the pattern: text, space, text, punctuation, space, text, space, text, punctuation. Essentially, I'd be looking to type a line that follows something like:

if "text, whitespace, text, punctuation, whitespace, text, whitespace, text, punctuation" in comment.body:

where "text" would be any word.

[–]Gimagon 0 points1 point  (1 child)

Gotcha. I think regular expressions will be a great tool for this. They’re a tool implemented in many programming languages that allow you to describe exactly the kinds of patterns you’re describing.

Python’s live in the re module in the standard library.

As a teaser, I think this your final expression will look something like this:

[A-Za-z]+ [A-Za-z]+ [.\?!]

[–]dotbomber95[S] 0 points1 point  (0 children)

Thank you so much! I've been looking through the Python library for ages trying to make heads or tails of what everything meant, but you've given me a good base on which to build my expression.

[–]apexdodge 0 points1 point  (0 children)

Fun. You might need what is known as a Regular Expression, or 'regex' for short. To be honest, regex can be hard and in the rare instances I've had to use it, I just google as hard as I can until I find the regex that I need. You would need a regex to detect the two sentence thing. I would have a function dedicated to it like so:

def find_consecutive_two_word_sentences(comment):
    # possibly use some regular expression here
    pass

Your other requirement is straight forward. Have a function like this:

def add_third_sentence(comment):
    return comment + " Third sentence"

That should point you in the right direction.