re.subn() method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

re.subn() method

how was the no of substitutions made end up being 4 in the output.help me understand https://code.sololearn.com/cIbPGncvGr9k/#py

11th Sep 2020, 11:21 AM
Mani
Mani - avatar
3 Answers
+ 3
As you said, it returns a tuple with the new string and how many substitutions. There were 4 spaces in the original, you subbed any space-like character, so the number of subs is 4.
11th Sep 2020, 11:57 AM
Slick
Slick - avatar
0
Slick Then shouldn't it be 6 ??
14th Sep 2020, 6:52 AM
Mani
Mani - avatar
0
nah, \s+ checks for one or more of the space like characters.Doing the same for, "\t \t" and " hi" would both count as 1
14th Sep 2020, 10:02 AM
Slick
Slick - avatar