I'm new in python
and while I was coding a little program I found a problem,
starting with a string like:
string = ('hello!')
I need to get a list like:
list = ['h','e','l','l','o','!']
How can i do?
I'm new in python
and while I was coding a little program I found a problem,
starting with a string like:
string = ('hello!')
I need to get a list like:
list = ['h','e','l','l','o','!']
How can i do?
Try:
s = 'hello!'
l = list(s)
print(l)
output
['h', 'e', 'l', 'l', 'o', '!']
Try this. It is called comprehension.
[i for i in strng]
Result:
['h', 'e', 'l', 'l', 'o', '!']