- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试删除字符串中出现的元音,除非它们是单词的开头。因此,例如像 “The boy is abt abt wn”
这样的输入应该输出 Th by is abt t wn
。这是我目前所拥有的。任何帮助将不胜感激!
def short(s):
vowels = ('a', 'e', 'i', 'o', 'u')
noVowel= s
toLower = s.lower()
for i in toLower.split():
if i[0] not in vowels:
noVowel = noVowel.replace(i, '')
return noVowel
最佳答案
一种方法是使用正则表达式替换前面没有单词边界的元音。此外,如果您的代码应该处理带有各种标点符号的任意文本,您可能需要考虑一些更有趣的测试用例。
import re
s = "The boy is about to win (or draw). Give him a trophy to boost his self-esteem."
rgx = re.compile(r'\B[aeiou]', re.IGNORECASE)
print rgx.sub('', s) # Th by is abt t wn (or drw). Gv hm a trphy t bst hs slf-estm.
关于python - 删除元音,除非它是单词的开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28446136/
我试图在 haskell 上创建一个函数,我知道该函数的定义如下: justWithA : [Char] -> Bool justWithA [] = True justWithA (x:xs) |
我试图在 haskell 上创建一个函数,我知道该函数的定义如下: justWithA : [Char] -> Bool justWithA [] = True justWithA (x:xs) |
我正在尝试计算字符串中元音的总数。我正在使用 strlen 来获取字符串的总长度,但是当我尝试按每个字母对字符串进行计数时,它说 C++ 禁止比较。所以我假设我的 if 语句有问题。 #include
Task You are given a string . It consists of alphanumeric characters, spaces and symbols(+,-). Your
我刚刚开始用 C 语言编程,我必须创建一个程序来计算字符串有多少个元音。到目前为止我有这个: int a; int len = strlen(text)-1 for(a=0;a==len;++a){
尝试学习 Python 中的正则表达式以查找具有连续元音-辅音或辅音-元音组合的单词。我将如何在正则表达式中执行此操作?如果无法在 Regex 中完成,是否有一种在 Python 中执行此操作的有效方
我想输入 dagger-alif、dagger-waw 和 dagger-ya(也称为微型 alif、微型哇和微型 ya)作为 alif-wasla 使用 PC 阿拉伯语键盘。这些标记被使用帮助读者发
我正在尝试创建一个将文件上传到 FTP 服务器的批处理文件。除了一个特定文件夹的名称中包含突变/元音外,一切正常(无法更改。也就是文件夹名称中包含 ö。)。 我的问题是:有哪些选择可以实现这一目标?
我是一名优秀的程序员,十分优秀!