Break string into list of characters in Python [duplicate] Break string into list of characters in Python [duplicate] python python

Break string into list of characters in Python [duplicate]


You can do this using list:

new_list = list(fL)

Be aware that any spaces in the line will be included in this list, to the best of my knowledge.


I'm a bit late it seems to be, but...

a='hello'print list(a)# ['h','e','l','l', 'o']


Strings are iterable (just like a list).

I'm interpreting that you really want something like:

fd = open(filename,'rU')chars = []for line in fd:   for c in line:       chars.append(c)

or

fd = open(filename, 'rU')chars = []for line in fd:    chars.extend(line)

or

chars = []with open(filename, 'rU') as fd:    map(chars.extend, fd)

chars would contain all of the characters in the file.