I have this list of strings:
x = ['+27', '05', '1995 F']
I want some code that outputs this:
['+', '27', '05', '1995', 'F']
I was thinking about using the .split()
function on the last element so I wrote this code:
x=['+27', '05', '1995 F']
x[2]=x[2].split()
This outputs:
['+27', '05', ['1995', 'F']]
How do ensure the 2nd element is not a sub-list, and instead output this?
['+27', '05','1995','F']
Should I use insert
and del
?
I wrote this for the first element using insert
and del
:
x=x.split("/")
x.insert(0,x[0][0])
x.insert(1,x[1][1:])
del x[2]
This outputs:
['+', '27', '05', '1995 F']
Is there a better way?