Nov-24-2019, 07:06 PM
I have another issue with converting a list into the formatting i need it and looking for advice. (possibly getting late in the evening and my brain has died :-( )
The current list format is as follows;
existinglist = [['A -> B', 1 ], ['C -> D', 4], ['F -> H', 6]]
I want to keep it in the same format but replace the -> as a comma, so it will have 3 indexes within each list. So i am trying to change the output to;
[['A', 'B', 1 ], ['C','D', 4], ['F','H', 6]]
My head seems to tell me the following code should work but i get an error telling me ''list' object has no attribute 'split'. Would be grateful for the solution and also if possible explanation of why my code gives this error (if possible)
My 'incorrect' effort:
Any help and advice would be gratefully appreciated.
The current list format is as follows;
existinglist = [['A -> B', 1 ], ['C -> D', 4], ['F -> H', 6]]
I want to keep it in the same format but replace the -> as a comma, so it will have 3 indexes within each list. So i am trying to change the output to;
[['A', 'B', 1 ], ['C','D', 4], ['F','H', 6]]
My head seems to tell me the following code should work but i get an error telling me ''list' object has no attribute 'split'. Would be grateful for the solution and also if possible explanation of why my code gives this error (if possible)
My 'incorrect' effort:
examplelist = [] for item in existinglist: examplelist .append(item.split('->'))Error message: 'list' object has no attribute 'split'
Any help and advice would be gratefully appreciated.