博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codewars第二天--Disemvowel Trolls
阅读量:4302 次
发布时间:2019-05-27

本文共 753 字,大约阅读时间需要 2 分钟。

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() 将元音字母替换为'' ,也就是空。

转载地址:http://smmws.baihongyu.com/

你可能感兴趣的文章
linux的基础知识
查看>>
接口技术原理
查看>>
五大串口的基本原理
查看>>
PCB设计技巧与注意事项
查看>>
linux进程之间通讯常用信号
查看>>
main函数带参数
查看>>
PCB布线技巧
查看>>
关于PCB设计中过孔能否打在焊盘上的两种观点
查看>>
PCB反推理念
查看>>
京东技术架构(一)构建亿级前端读服务
查看>>
git 提示:error: unable to rewind rpc post data - try increasing http.postBuffer
查看>>
php 解决json_encode中文UNICODE转码问题
查看>>
LNMP 安装 thinkcmf提示404not found
查看>>
PHP empty、isset、innull的区别
查看>>
apache+nginx 实现动静分离
查看>>
通过Navicat远程连接MySQL配置
查看>>
phpstorm开发工具的设置用法
查看>>
Linux 系统挂载数据盘
查看>>
Git基础(三)--常见错误及解决方案
查看>>
Git(四) - 分支管理
查看>>