Hackbright Code Challenges

Truncate Repeats

Truncate Repeats

Whiteboard

Easier

Challenge

Easier

Concepts

Strings, Loops

Download

truncate-repeats.zip

Solution

Truncate Repeats: Solution


Write a function that takes in a string and returns a string where any repeating characters have been truncated to one character. For example:

>>> truncate('aaaaabbbbbcccaaaa')
'abca'

>>> truncate('hi there')
'hi there'

>>> truncate('hi   !!! wooow')
'hi ! wow'

We’ve provided a function stub and tests in truncate-repeats.py.