+ 2
Need some help with regex method finditer()
can anyone explain why I have to perform re assignment of n before using it again https://code.sololearn.com/c2QlXYEG5Vq9/?ref=app
6 ответов
+ 2
You can considerate an iterator like an way to get only next elements. When you arrive to last one, you cannot go next at all, then iterator going not more useful anymore. Futhermore any time that you get an iterator from an iterable object, you get different iterators. In your case, any time that you loop on all items on iterator, for request items again you have to get another iterator because if you use old one, you cannot get other items (you have readed yet last and you can get only next item)
+ 1
that's really helpful thanks KrOW
+ 1
👍👍👍
+ 1
Sandeep Rana Because re.findall return only matched groups if least one group exists in pattern... Try to set the pattern like r"(egg(spam)*)" and you will get a tuple list containing all groups match (included your all pattern string).... For more info go to python docs site
+ 1
thanks man. this one helps.
0
KrOW I have another question. I don't understand why it doesn't give 'egg' instead of '' and eggspamspam instead of 'spam'. read the comment in the updated code.