'string python function to summarize data - code problem
I made the string function in pythonbelow to summarize a block of text. I'm not getting any final answer when I run the function. Can someone help figure out what I did wrong? Thanks.
def summary(data):
category = data.get("category", "")
article_date = data.get("date", "")
headline = data.get("headline", "")
return summary(data)
pass
Solution 1:[1]
You are recursively calling the summary function. Assuming that the code provided is the entire function, if you want to get any output, you'd need to use something like this rather than calling the function again. You would also have to print the return value of the function
def summary(data):
category = data.get("category", "")
article_date = data.get("date", "")
headline = data.get("headline", "")
return f"Category: {category}\nArticle Date: {article_date}\nHeadline: {headline}\n"
pass
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Uncle Maximilian |