mayank pareek
mayank pareek

Reputation: 71

words splitting to letters when making a list out of them in python

I am trying to create a list of words or phrases in python 3. For example;

a = ('Hello World')

when i am trying to convert it to a list, this happens,

list(a)

['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

but i want it to be ['Hello World']

Please can anyone help?

Upvotes: 0

Views: 22

Answers (2)

Guimoute
Guimoute

Reputation: 4629

You simply want to use [a] instead of list(a).

Upvotes: 1

Sachin Sachin
Sachin Sachin

Reputation: 11

a='hello world' create a list object then add the string object into list object using list built in function n=[] n.append(a) print(n)

Upvotes: 0

Related Questions