Tokenize a string: Difference between revisions

Content added Content deleted
(Nicer variable names)
Line 226: Line 226:
'''Interpreter:''' Python 2.5
'''Interpreter:''' Python 2.5


words = "Hello,How,Are,You,Today"
text = "Hello,How,Are,You,Today"
list_of_words = words.split(',')
tokens = text.split(',')
print '.'.join(list_of_words)
print '.'.join(tokens)


If you want to print each word on its own line:
If you want to print each word on its own line:


for word in list_of_words:
for token in tokens:
print word
print token


or
or


print "\n".join(list_of_words)
print "\n".join(tokens)


==[[Ruby]]==
==[[Ruby]]==