complexstring: '2,3-5,50-52,70'
output required: [2,3,4,5,50,51,52,70]
Here is what I attempted and succeeded
a = '2,3-5,50-52,70'
data = []
[data.extend(range(int(r.split('-')[0]),int(r.split('-')[1])+1)) if r.find('-') != -1 else data.append(int(r)) for r in a.split(',')]
print data
output achieved: [2, 3, 4, 5, 50, 51, 52, 70]
But my question is there a way to do in place with in list comprehension? What I exactly mean is
data = [#perform some processing on a here to get directly output]
instead of pre-declaring list data
and keep appending or extending it.
P.S: I want to achieve it with just list comprehension without defining additional function.