1

I know that:

print(list('Hello'))

will print

['H', 'e', 'l', 'l', 'o']

and I know that

print(list('Hello world!'))

will print

['Hello', 'world!']

What syntax would be easiest to get:

['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!']
0

2 Answers 2

16

list('Hello world!') gives what you want, not ['Hello', 'world!'].

>>> print(list('Hello world!'))
['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!']

I think you confused the output of str.split:

>>> print('Hello world!'.split())
['Hello', 'world!']
Sign up to request clarification or add additional context in comments.

Comments

2

work under python 3.6

 a = "Hello world!"
 listresp = list(map(list, a))
 listff =[]
 print (listresp)
 for charersp in listresp:
     for charfinnal in charersp:
         listff.append(charfinnal)
 print (listff)


 ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.