Post

Came up with 4 random ways to do this. 2, I recommend you use them (although 1 doesn't work!) The other 2 are really cool — they use fixed points and `itertools.groupby` — but they'll be overkill 99.9% of times.

How do you collapse runs of adjacent spaces in Python? That is, shorter runs of 2+ consecutive spaces so there's only 1 space there? I can't come up with a simple/straightforward way to do it with `str.join` and I'm surprised... What am I missing?

0 reposts0 likes

No replies yet.