0

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?

sentence
  • 8,213
  • 4
  • 31
  • 40

2 Answers2

1

Try:

s = 'hello!'

l = list(s)
print(l)

output

['h', 'e', 'l', 'l', 'o', '!']
sentence
  • 8,213
  • 4
  • 31
  • 40
1

Try this. It is called comprehension.

[i for i in strng]

Result:

['h', 'e', 'l', 'l', 'o', '!']
jose_bacoy
  • 12,227
  • 1
  • 20
  • 38