python - Python在字符串中查找首字母大写后跟字母数字字符的单词
问题描述
输入:"We are Testing."
输出:['We', 'Testing']
输入:"Hello1 Hello2 Hello3"
输出:['Hello1', 'Hello2', 'Hello3']
如果字符串中没有这样的单词,则返回 'None'
有没有一种有效的方法来解决这个问题,我尝试拆分字符串,但似乎效果不佳。
解决方案
函数将字符串作为参数并对其进行处理
def finder(string):
words_list = string.split(' ')
# Check if the first letter is uppercase and is alphanumerical
# Else remove the word from list
words_list = [i for i in words_list if i == i.capitalize() and i.isalnum()]
return words_list
推荐阅读
- java - 错误:没有为参数 1 指定值
- android - 无法解决:firebase-common
- facebook - Facebook Graph API:获取到用户时间线的链接不起作用
- google-chrome-extension - 如何使用 AngularJS 在此页面中设置日期
- javascript - HTML5 前后比较滑块
- c - 在 C 中编写 bmp 文件会产生错误的结果
- javascript - WKWebView - JavaScript 警报功能在 Objective-C 中不起作用
- android - Unity GooglePlayGamesPlugin 包导入问题
- meteor - Meteor Tracker.autorun 行为
- c++ - 类型名的概念/SFINAE 错误