+ 7

Challenge : compressing lists with successive numbers

You want to compress a list by replacing successions of numbers with the corresponding range. Ex : [-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]) ==> "-6,-3-1,3-5,7-11,14,15,17-20" Write the program doing this compression. Oneliners welcomed !

2nd Feb 2018, 5:55 PM
VcC
VcC - avatar
9 Answers
+ 3
It seems impossible to write in one line... Separate input numbers with spaces. https://code.sololearn.com/cqNjsJ4xe2SV/?ref=app
2nd Feb 2018, 6:30 PM
Petr Leliaev
Petr Leliaev - avatar
+ 3
https://code.sololearn.com/cdsmnQQS0Tcr/#py EDIT: @VcC oops! my bad! fixed it :) it's not even close to be as short as you've shown to be possible, but it does the job :p
3rd Feb 2018, 4:57 PM
Pedro Demingos
Pedro Demingos - avatar
+ 2
Oneliners friends where are you ? https://code.sololearn.com/c82XfKVLiK5G/?ref=app
3rd Feb 2018, 6:29 AM
VcC
VcC - avatar
+ 1
@VcC I have fixed the code, thanks for your comments!
2nd Feb 2018, 7:40 PM
Petr Leliaev
Petr Leliaev - avatar
13th Feb 2018, 8:54 AM
sayan chandra
sayan chandra - avatar
0
Not impossible ! Can provide test input or use the proposed format to facilitate testing ?
2nd Feb 2018, 6:46 PM
VcC
VcC - avatar
0
@VcC for example, 3 7 8 9 10 14 21 22 23
2nd Feb 2018, 6:52 PM
Petr Leliaev
Petr Leliaev - avatar
0
Good work but not 100% ok. check the proposed example
2nd Feb 2018, 7:13 PM
VcC
VcC - avatar