Python Forum
Splitting String into 2d list - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Splitting String into 2d list (/thread-20703.html)



Splitting String into 2d list - cclark135 - Aug-26-2019

I have a sample list of data as follows

'762-69-7639,Aime,Gentzsch,12ALT,ENG LIT,MUSIC,PSYCHOL
359-53-2130,Marrick,Spinelli,12POL,MATHS,COMPSCI,PHYSICS
460-96-3787,Isaac,Keese,12SIR,ENG LIT,DRAMA,SOCIOL'
etc...

And I want to split the entire string into a 2d list. The first set of lists being each line and the second being each element (minus the commas) and also without having the /n at the end of every list.
So for example:


[['762-68-7639', 'Aime', 'Gentzsch', 12ALT, 'ENG LIT', 'MUSIC', 'PSYCHOL']['359-53-2130', 'Marrick', 'Spinelli', '12POL', 'MATHS', 'COMPSCI', 'PHYSICS']['460-96-3787', 'Issac', 'Keese', '12SIR', 'ENG LIT', 'DRAMA', SOCIL]]
Is there an easy way to make both the splits at once or if somebody can demonstrate a possible method to split the list up as how i described.


RE: Splitting String into 2d list - buran - Aug-26-2019

what have you tried? show your code in python tags, any traceback - in error tags.


RE: Splitting String into 2d list - ThomasL - Aug-26-2019

This might be helpful....