Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar: HTML Is Just Strings
- # see also Make Tag exercise on CodingBat: https://codingbat.com/prob/p132290
- myString = "<p>Furley to buy complex from Ropers</p>"
- myString = myString.replace("<p>", "<h1>")
- myString = myString.replace("</p>", "</h1>")
- print(myString)
- myContainer = ("peanut butter", "bread", "milk", "cheese puffs")
- # say we want this output:
- # <ul>
- # <li>peanut butter</li>
- # <li>bread</li>
- # <li>milk</li>
- # <li>cheese puffs</li>
- # </ul>
- # ... treat the OUTPUT as THE STRING YOU WANT TO BUILD
- myHTMLString = "<ul>\n"
- for item in myContainer:
- myHTMLString += "<li>{}</li>\n".format(item)
- myHTMLString += "</ul>"
- print(myHTMLString)
- # or we could do the same with any parent + nested child combo
- # say we wanted a div with paragraphs instead
- myHTMLString = "<div>\n"
- for item in myContainer:
- myHTMLString += "<p>{}</p>\n".format(item)
- myHTMLString += "</div>"
- print(myHTMLString)
Add Comment
Please, Sign In to add comment