2.使用def slugify(text, delimiter='-'):
>>> slugify("These aren't the droids you're looking for.")
'these-aren-t-the-droids-you-re-looking-for'
>>> slugify('A Man, A Plan, A Canal – Panama!', delimiter='_')
'a_man_a_plan_a_canal_panama'
>>> slugify('No delimiter!', delimiter='')
'nodelimiter'
>>> slugify(' Spaces before and after ')
'spaces-before-and-after'
我只知道一种写法,但是能不能用def slugify(text, delimiter='-'):
def slugify(s):
s = s.lower().strip()
s = re.sub(r'[^\w\s-]', '', s)
s = re.sub(r'[\s_-]+', '-', s)
s = re.sub(r'^-+|-+$', '', s)
return s
slugify("These aren't the droids you're looking for.")但是不对
3.这个很懵圈...
def summary(data):
Example:
{
'authors': 'Melissa Jeltsen',
'category': 'CRIME',
'date': '2018-05-26',
'headline': 'There Were 2 Mass Shootings In Texas Last Week, But Only 1 On TV',
'link': 'https://www.huffingtonpost.com/entry/texas-amanda-painter-mass-shooting_us_5b081ab4e4b0802d69caad89',
'short_description': 'She left her husband. He killed their children. Just another day in America.'
}
Returns:
"May, 2018. Crime. There Were 2 Mass Shootings In Texas Last Week, Bu"
category = data.get("category", "")
article_date = data.get("date", "")
headline = data.get("headline", "")
data=format(category,article_date,headline)
return data