I have a list with only 1 element which is a String of 2 characters, my goal is to separate those 2 characters so that the list has 2 characters, I am not finding an alternative to solve it, I have seen and tried using split()
, but even so I did not get the desired result.
My list is as follows:
Pila = ['+Z']
and the way it should be is as follows:
Pila = ['+','Z']
How could I get it?
you could convert to another list, the value of the current list, you could try something like this.
You can do it in several ways, the simplest thing would be to remove the list and keep it as a simple
str
. He left you some.Loop
You can do it with a loop, for example a
for
. What it does is iterate through each character.Departure:
['+', 'Z']
It will also give you the same using List Comprehension
Ready
Using
list
Python automatically iterates through the elements to create the list, so you can simply use that in yourstring
Departure:
['+', 'Z']
Of course it can also be done with
tuple
orset
map with lambda
You can use a lambda function that extracts each character with
map
Departure:
['+', 'Z']
First, I recommend you look up PEP or the Python rules, for example never start a variable with a capital letter
Second, the simplest solution would be:
Cheers