【发布时间】:2017-07-01 15:12:54
【问题描述】:
如果我有一个类似的列表
list = ['helloA', 'hiA', 'helloB', helloC']
我想计算该列表中出现的子字符串 'hello' 的数量。
编辑:
其实我已经有办法像下面这段代码那样计算它了:
numb = [x for x,y in enumerate(data['column']) if 'sub-string' in y]
print len(numb)
我只是想知道是否有其他方法或更好的方法来做到这一点。 谢谢
【问题讨论】:
-
你是如何计算子串的?
['hellohello']会有 1 还是 2?['hel', 'lo']是 1 还是 0? -
@Artyer
['hellohello']将被计为 1。我的意思是计算列表中包含子字符串的字符串数。 -
@FrancescoMontesano 好的,对不起。我将编辑问题。
标签: python regex python-2.7 list count