I am new to Python and I want to know am controlling the flow of the program correctly. I am wondering if the following method is the correct way to return a value from a method.
extract_nouns()
retunes an empty string if there are no nouns in news_story
, the same with extract_numbers()
. If search terms.
find_news()
returns a list of Story
objects if there are any stories, or None
if no news story are found.
find_similar_news_stories()
returns None
unless there is a story to return.
Is this correct, or does it look wrong? Should I explicitly return None
if I find no stories. Should I pass an empty list from find_news()
to the method that calls find_similar_stories()
and handle the checking of list there?
def find_similar_news_stories(self, news_story):
nouns = self.extract_nouns(news_story)
numbers = self.extract_numbers(news_story)
search_terms = nouns + numbers
if search_terms != "":
stories = self.find_news(search_terms)
if stories != None:
return stories
stories = self.find_news(nouns)
return stories