Codewars第二天--Disemvowel Trolls

41 篇文章 1 订阅

Codewars第二天–Disemvowel Trolls

继续刷题,题目描述为:
Trolls are attacking your comment section!
A common way to deal with this situation is to remove all of the vowels from the trolls' comments, neutralizing the threat.
Your task is to write a function that takes a string and return a new string with all vowels removed.
For example, the string "This website is for losers LOL!" would become "Ths wbst s fr lsrs LL!".
Note: for this kata y isn't considered a vowel.

题目描述很好玩,和LOL有关。
要求是需要将评论中的元音字母 从字符串中删除。并返回删除后的字符串。并且y不算做元音。这个题也很简单,我们只需要找出字符串中的元音字母aeiou 及他们的大小形式AEIOU ,然后删除他们即可。

代码如下:

def disemvowel(string):
    s = 'aeiouAEIOU'
    for i in range(len(s)):
        string = string.replace(s[i], '')


    return string

创建一个元音字母构成的新字符,通过遍历使用replace() 将元音字母替换为'' ,也就是空。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值