小编App*_*e27的帖子

Python:在字符串中添加字符的副本

我试图找出如何在字符串中添加字符的副本,只要字符是元音.例如,如果我输入单词copy('app'),理想情况下它将返回'aaaapp!'.我知道字符串是不可变的,但必须有一种方法!我一直盯着这几个小时.

注意:我不想要我的代码解决方案,最好只是提示让我朝着正确的方向前进.编辑:感谢您的帮助!

我的一个想法是:单词+ =单词+ i*4,但返回的内容类似'appaaaa!'

def copy(word):
     "('string') ==> ('string') Adds four copies of vowel and an '!' to the string"
     vowel = 'aeiouAEIOU'
     for i in word:
          if i in vowel:
                #Missing code Here
     return word + '!'
Run Code Online (Sandbox Code Playgroud)

python string character

3
推荐指数
1
解决办法
3083
查看次数

标签 统计

character ×1

python ×1

string ×1