python any和all的用法, 可以查找某些字符串是否存在
2016-08-10 11:12
597 查看
有一个长字符串, 还有一个列表, 其中有一些短字符串
查找长字符串是否包含列表中的某个字符串, 只要包含就返回True
想要查找, 这个长字符串中是否包含那个列表中的所有字符串
字符串查找和替换 的用法
查找长字符串是否包含列表中的某个字符串, 只要包含就返回True
>>> x = ["aa", "bb", "cc", "dd", "ee", "ff"] >>> s = "ttcaceekktlffc" >>> any((s.find(k) != -1) for k in x) True >>>
想要查找, 这个长字符串中是否包含那个列表中的所有字符串
>>> all((s.find(k) != -1) for k in x) False
字符串查找和替换 的用法
>>> "tta".find("t") 0 >>> if "tta".find("t") != -1: ... print "match." ... >>> if "tta".find("t") == -1: ... print "not found" ... else: ... print "found" ... found >>> "tta".replace("t","mt") 'mtmta' >>> "tta".replace("at","mt") 'tta' >>> "tta".replace("ta","mt") 'tmt' >>> any(x) # x中包含 不为0或不是空字符串的元素 True >>> all(x) # x中所有元素都不为0, 也不是空字符串 True
相关文章推荐
- java String 查找字符串是否存在方法 --> IndexOf 用法
- python 查找字符串是否存在实例详解
- C语言-在一个字符串中查找是否存在另外一个字符串+查找字符串大写字母个数
- php strstr查找字符串中是否包含某些字符的查找函数
- python中map、any、all函数用法分析
- [码海拾贝 之Perl]在字符串数组中查找特定的字符串是否存在
- 一月十日练习习题,1数组数据存入字典并输出2降序 和倒叙 输出数组中内容3对字符串当中信息进行查找是否存在4 把数组当中信息按照中文排序
- 查找指定字符串在数组中是否存在
- 字符串比较函数strncasecmp():比较字符串的前n个字符|字符串查找函数strstr和string.find() 查找字符串str1中是否存在与str2一样的子字符串
- 查找某些字符是否在另一个字符串里出现的高效算法
- Linux查找某些文件中是否含有特定字符串
- Ubuntu 12.04 LTS 更新源方法(加快获取软件的速度,查找某些包是否存在,更新某些常用软件)
- 查找某些字符是否在另一个字符串里出现的高效算法
- 在Python中用has_key()方法查找键是否存在的教程
- php 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等
- 利用空间换时间来快速查找字符是否存在某个字符串里
- Excel 某单元格查找在某列中是否存在,存在就插入或拷贝值到指定单元格 VLOOKUP IF嵌套用法
- matlab自学经验成果分享 查找字符串中是否存在指定字符
- 查找某些字符是否在另一个字符串里出现的高效算法