Python: String split and for each

Categories: Python; Tagged with: ; @ April 23rd, 2014 0:49

This example shows how to split string and do for…each in Python:

>>> rawTags = 'TAG1 TAG2 TAG3 TAGB1 TAGB2'
>>> tags = rawTags.split()
>>> tags
['TAG1', 'TAG2', 'TAG3', 'TAGB1', 'TAGB2']
>>> output = ''
>>> for tag in tags:
... output += '"' + tag + '",'
>>> output
'"TAG1","TAG2","TAG3","TAGB1","TAGB2",'

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.