Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (12.7k points)

How might I turn a string (like 'hello') into the following list (like [h,e,l,l,o])?

1 Answer

0 votes
by (26.4k points)

The list() function will change over a string into a list of single-character strings. 

>>> list('hello')

['h', 'e', 'l', 'l', 'o']

Indeed, even without changing them over to lists, strings as of now act like lists severally. For instance, you can get to individual characters (as single-character strings) utilizing brackets: 

>>> s = "hello"

>>> s[1]


>>> s[4]


You can likewise loop over the characters in the string so that you can loop over the components of a list:

>>> for c in 'hello':

...     print c + c,


hh ee ll ll oo

Interested to learn python in detail? Come and Join the python course.

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.7k users

Browse Categories