+ 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

6th Jun 2018, 9:01 PM
Sandeep Rana
6 Respostas
+ 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)
6th Jun 2018, 11:48 PM
KrOW
KrOW - avatar
+ 1
that's really helpful thanks KrOW
7th Jun 2018, 6:58 AM
Sandeep Rana
+ 1
👍👍👍
7th Jun 2018, 7:06 AM
KrOW
KrOW - avatar
+ 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
7th Jun 2018, 8:32 AM
KrOW
KrOW - avatar
+ 1
thanks man. this one helps.
7th Jun 2018, 9:22 AM
Sandeep Rana
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.
7th Jun 2018, 7:39 AM
Sandeep Rana