Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to remove special characters from the list using python?

I have a list like this.

z=[']\'What type of humans arrived on the Indian subcontinent from Africa?\', \'When did humans first arrive on the Indian subcontinent?\', \'What subcontinent did humans first arrive on?\', \'Between 73000 and what year ago did humans first arrive on the Indian subcontinent?\',\kingdoms were established in Southeast Asia?Indianized\']']

I want to convert it into simple 2d list.

z= [['What type of humans arrived on the Indian subcontinent from Africa?', 'When did humans first arrive on the Indian subcontinent?', 'What subcontinent did humans first arrive on?', 'Between 73000 and what year ago did humans first arrive on the Indian subcontinent?','kingdoms were established in Southeast Asia?Indianized']]

so how to convert this list into 2D list?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The logic is not fully clear. I’d approach it using a regex on 2 or more non-word character to split:

[[x for x in re.split(r'[^a-z0-9\?]{2,}', s, flags=re.I) if x] for s in z]

output:

[['What type of humans arrived on the Indian subcontinent from Africa?',
  'When did humans first arrive on the Indian subcontinent?',
  'What subcontinent did humans first arrive on?',
  'Between 73000 and what year ago did humans first arrive on the Indian subcontinent?',
  'kingdoms were established in Southeast Asia?Indianized']]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading