Logo

Programming-Idioms

History of Idiom 219 > diff from v7 to v8

Edit summary for version 8 by Oldboy:
New Python implementation by user [Oldboy]

Version 7

2020-02-29, 15:42:47

Version 8

2020-03-02, 08:16:24

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Extra Keywords
collapse repeated
Extra Keywords
collapse repeated
Imports
import re
Code
t = re.sub(' +', ' ', s)
Comments bubble
only replaces spaces