list of char to string python code example
Example 1: how to join a list of characters in python
>>> a = ['a', 'b', 'c', 'd']
>>> ''.join(a)
'abcd'
Example 2: python string to list of chars
l = list('abcd') # ['a', 'b', 'c', 'd']
l = map(None, 'abcd') # ['a', 'b', 'c', 'd']
l = [i for i in 'abcd'] # ['a', 'b', 'c', 'd']
import re # importing regular expression module
l = re.findall('.', 'abcd')
print(l) # ['a', 'b', 'c', 'd']
Example 3: how to save string characters into char array or list in python
fd = open(filename, 'rU')
chars = []
for line in fd:
chars.extend(line)