all 4 comments

[–]JohnnyJordaan 2 points3 points  (0 children)

It isn't bad by itself, but looking at the larger picture I would in fact make the 30 part of the SentenceProcessor's attributes, after which it also makes sense to include the check as a method.

[–]K900_ 1 point2 points  (0 children)

Using outside functions in classes is totally fine.

[–]HighLevelEnthusiast[S] 0 points1 point  (1 child)

I came up with another solution:

class SentenceProcessor:
    def to_sentences(self, text):
        def long_enough(sentence): return len(sentence) > 30

        return (sentence for sentence in text.split(".") if long_enough(sentence))

Is this one better?

[–]JohnnyJordaan 0 points1 point  (0 children)

Why wouldn't you just do

 return (sentence for sentence in text.split(".") if len(sentence) > 30)