0

I can't able to delete the extra comma from the below list of strings

[',156,151,2016-06-07',',160,147,2016-03-16',',99,91,2016-06-11']

I tried to use join and delete but it didn't work

expecting the result like below

['156,151,2016-06-07','160,147,2016-03-16','99,91,2016-06-11']

please help me...thanks in advance

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223

3 Answers3

1

You can use a list-comprehension:

>>> l = [',156,151,2016-06-07',',160,147,2016-03-16',',99,91,2016-06-11']
>>> l = [i.lstrip(',') for i in l]
>>> l
['156,151,2016-06-07', '160,147,2016-03-16', '99,91,2016-06-11']
mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
0

Just use str.replace:

newArr = []
for line in arr:
    newArr.append(line.replace(',', '')
Athena
  • 3,200
  • 3
  • 27
  • 35
0

you can use list comprehension for the same :-

>>> l= [',156,151,2016-06-07',',160,147,2016-03-16',',99,91,2016-06-11']
>>> [i.lstrip(',') for i in l]
['156,151,2016-06-07', '160,147,2016-03-16', '99,91,2016-06-11']
Pabitra Pati
  • 457
  • 4
  • 12