楼主: 番茄奏鸣曲
5213 0

[问答] 自动识别单词并插入“-” [推广有奖]

  • 0关注
  • 0粉丝

硕士生

60%

还不是VIP/贵宾

-

威望
0
论坛币
1808 个
通用积分
32.1968
学术水平
0 点
热心指数
4 点
信用等级
0 点
经验
6004 点
帖子
92
精华
0
在线时间
150 小时
注册时间
2012-2-20
最后登录
2022-4-28

楼主
番茄奏鸣曲 发表于 2022-3-14 13:02:46 |AI写论文
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










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

关键词:Hello World Description delimiter Category headline

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-13 15:55