Given the following problem,
Input
lis = ['0-10,000, 10,001-11,000, 11,001-12,000']
Output:
['0-10,000','10,001-11,000', '11,001-12,000']
Create a function such that, it should avoid if there's a single range in the list but split the ranges if there are multiple ranges in the list.
Can anybody help me with this problem, I can't even think of any method.
CodePudding user response:
First build a string from the list of elements, then split the string with the specified ", ".
lis = ['0-10,000, 10,001-11,000, 11,001-12,000']
print(''.join(lis).split(", "))
CodePudding user response:
I have tried this :
lis = ['0-10,000, 10,001-11,000, 11,001-12,000','0-10,001, 10,001-11,000, 11,001-12,000','0-10,011, 10,001-11,000, 11,001-12,000']
def data_clean(x):
v = []
for i in range(len(x)):
v.append(x[i].split(", "))
return v
Here it is how the output is :
[['0-10,000', '10,001-11,000', '11,001-12,000'],
['0-10,001', '10,001-11,000', '11,001-12,000'],
['0-10,011', '10,001-11,000', '11,001-12,000']]