全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 python论坛
5214 0
2022-03-14
悬赏 1 个论坛币 未解决
1. 使用 def inject(s, i):
希望得到的结果(包括数字和字符)希望得到的结果是
inject('Hello world', 'x')
‘Hxexlxlxox xwxoxrxlxd'


inject(7334, 3)
'7333334'


return reduce(lambda r,v: r+[i,v], s[1:], s[:1]) 这么写会报错....



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










这样为什么不对啊(类目....)

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群