Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 41 characters in body
Source Link
U13-Forward
  • 2k
  • 10
  • 35

Python 3, 91(削除) 91 (削除ここまで) 90 bytes

lambda x:''.join(l!="0"andl>"0"and l or f'{len([*g])}'for l,g in groupby(x))
from itertools import*

Try it online! Try it online!

-1 byte thanks to The Thonnu

I use the itertools module's groupby function to group consecutively.

Python 3, 91 bytes

lambda x:''.join(l!="0"and l or f'{len([*g])}'for l,g in groupby(x))
from itertools import*

Try it online!

I use the itertools module's groupby function to group consecutively.

Python 3, (削除) 91 (削除ここまで) 90 bytes

lambda x:''.join(l>"0"and l or f'{len([*g])}'for l,g in groupby(x))
from itertools import*

Try it online!

-1 byte thanks to The Thonnu

I use the itertools module's groupby function to group consecutively.

Source Link
U13-Forward
  • 2k
  • 10
  • 35

Python 3, 91 bytes

lambda x:''.join(l!="0"and l or f'{len([*g])}'for l,g in groupby(x))
from itertools import*

Try it online!

I use the itertools module's groupby function to group consecutively.

AltStyle によって変換されたページ (->オリジナル) /