-1

I have a list containing text data from a docx file. How can I apply some regex or some lambda function to go through this whole list and 'clean it'; meaning, I'd like to take out \t and \n

['\tSA   [WP5]\t\t\n', "<class 'docx.text.paragraph.Paragraph'>\n", '\t\tCOUNTRY:\n', "<class 'docx.text.paragraph.Paragraph'>\n", '\n']

so that my output looks like:

['SA   [WP5]', "<class 'docx.text.paragraph.Paragraph'>", 'COUNTRY:', "<class 'docx.text.paragraph.Paragraph'>", '']
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
sgerbhctim
  • 3,420
  • 7
  • 38
  • 60

1 Answers1

1
[x.replace('\t', '').replace('\n', '') for  x in lst] 

would do it, without the need for regex.

jez
  • 14,867
  • 5
  • 37
  • 64