AttributeError: 'list' object has no attribute 'split'
2 answers
You can simply do list(myList[0])
as below:
>>> myList = ['hello']
>>> myList=list(myList[0])
>>> myList
['h', 'e', 'l', 'l', 'o']
See documentation here
+2
source to share
To achieve what you are looking for:
myList = ['hello']
result = [c for c in myList[0]] # a list comprehension
>>> print result
['h', 'e', 'l', 'l', 'o']
More information on lists: http://www.secnetix.de/olli/Python/list_comprehensions.hawk
Lists in python don't have a split method. split is a string ( str.split()
) method
Example:
>>> s = "Hello, please split me"
>>> print s.split()
['Hello,', 'please', 'split', 'me']
By default, the separation is split into spaces.
More information: http://www.tutorialspoint.com/python/string_split.htm :
+1
source to share