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 i split this list into the same list without creating new list

how do I split this list

['charmander|4/16/2022 18:5:52|Good to see you!', 'charmander|4/16/2022 18:6:0|Good to see you!']

to

['charmander', '4/16/2022 18:5:52', 'Good to see you!' , 'charmander', '4/16/2022 18:5:52', 'Good to see you!']

by the way, this list is part of a txt file and has been split already by doing this

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

file = open('messages/' + username + '.txt', 'r')

data = file.read().strip()

results = data.split("\n")

>Solution :

You can do it like this using string.split("|")

l = ['charmander|4/16/2022 18:5:52|Good to see you!', 'charmander|4/16/2022 18:6:0|Good to see you!']
newList = []
for val in l:
    newList += (val.split("|"))

Output:
['charmander',
 '4/16/2022 18:5:52',
 'Good to see you!',
 'charmander',
 '4/16/2022 18:6:0',
 'Good to see you!']

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