0 votes
1 view
in Python by (8.4k points)
edited by

Suppose this is the string:

The   fox jumped   over    the log.

​​​​​​It would result in:

The fox jumped over the log.

What is the simplest, 1-2 liner that can do this? Without splitting and going into lists...

1 Answer

0 votes
by (16.8k points)

Try as shown below:

>>> import re

>>> re.sub(' +', ' ', 'The     quick brown    fox')

'The quick brown fox'

Related questions

+1 vote
1 answer
+2 votes
1 answer
0 votes
0 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...