我正在使用模块中的finditer
函数re
来匹配某些东西,并且一切正常。
现在,我需要找出我有多少场比赛。是否可以不两次遍历迭代器?(先找出计数然后是真正的迭代)
一些代码:
imageMatches = re.finditer("<img src\=\"(?P<path>[-/\w\.]+)\"", response[2])
# <Here I need to get the number of matches>
for imageMatch in imageMatches:
doStuff
一切正常,我只需要在循环之前获取匹配数即可。