I am trying to add a "- " to the beginning of each new line in a string. Here is my code:The output is:PHP Code:
#! /usr/bin/env python
#
text = "First Line\nSecond Line\nThird Line"
print text
text_group = text.split("\n")
for nl in text_group:
spaced = "- %s" % nl
print spaced
print spaced
When I print from inside the "for" loop, each line is printed. But if I print outside the loop, only the last line is printed. How can I get all lines to print outside the loop?Code:First Line Second Line Third Line - First Line - Second Line - Third Line - Third Line
Bookmarks