首页 > 其他分享 >Disemvowel Trolls

Disemvowel Trolls

时间:2023-03-17 23:33:37浏览次数:19  
标签:return string vowels Disemvowel 字符串 join Trolls

Instructions
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.
Solution

def disemvowel(string):
    return "".join(c for c in string if c.lower() not in "aeiou")

join() 是一个字符串方法,它用于将序列中的元素连接成一个字符串。该方法接受一个参数,即要连接的序列,然后返回一个新的字符串。
例如,如果我们有一个包含三个字符串的列表 words = ['one', 'two', 'three'],我们可以使用 join() 方法将这些单词连接起来,如下所示:
separator = ' '
result = separator. Join(words)
print(result)
这段代码会输出 "one two three"。
注意,在这个例子中,我们使用空格作为分隔符来连接单词。你可以使用任何字符串作为分隔符。

标签:return,string,vowels,Disemvowel,字符串,join,Trolls
From: https://www.cnblogs.com/artwalker/p/17228635.html

相关文章