[Tutor] Split Method

Rafael Knuth rafael.knuth at gmail.com
Thu Jan 30 12:11:56 CET 2014


Hey there,

I am having some issues with splitting strings.
I already know how to split strings that are separated through empty spaces:

def SplitMyStrings():
    Colors = "red blue green white black".split()
    return (Colors)

print(SplitMyStrings())

>>>
['red', 'blue', 'green', 'white', 'black']

... however I couldn't figure out how to split each character into a list item.
This is what I want to get as a result:

>>>
['r', 'e', 'd', 'b', 'l', 'u', 'e', 'g', 'r', 'e', 'e', 'n', 'w', 'h',
'i', 't', 'e', 'b', 'l', 'a', 'c', 'k']

I am using Python 3.3.0
Thanks in advance!

All the best,

Raf


More information about the Tutor mailing list