MAK
MAK

Reputation: 7260

Python 2.7: Remove part of element in SET

The given set is:

seta = (['3;\t103;\tB03;\t01-06-2018;\t10:23:20;\t07:15:10\n',
         '10;\t110;\tB10;\t01-06-2018;\t10:30:00;\t07:40:10\n'])

Need to remove \t, expected set should look like:

['3,103,B03,01-06-2018,10:23:20,07:15:10\n',
 '10,110,B10,01-06-2018,10:30:00,07:40:10\n']

Upvotes: 1

Views: 39

Answers (2)

Suyog Jadhav
Suyog Jadhav

Reputation: 325

You can simply use simple python one-liner

    seta = [string.replace(";\t", ", ") for string in seta]

Hope it helped!

Upvotes: 0

Austin
Austin

Reputation: 26039

Use replace:

seta = (['3;\t103;\tB03;\t01-06-2018;\t10:23:20;\t07:15:10\n', '10;\t110;\tB10;\t01-06-2018;\t10:30:00;\t07:40:10\n'])
print([x.replace(';\t', ',') for x in seta])

# ['3,103,B03,01-06-2018,10:23:20,07:15:10\n', '10,110,B10,01-06-2018,10:30:00,07:40:10\n']

Upvotes: 2

Related Questions