This function simply takes a single-dimension sequence and converts into into an HTML unordered list. This function makes it simple to present the contents of a sequence on the web in an neat fashion.
1 2 3 4 5 6 7 8 9 10 | def SequenceToUnorderedList(seq):
html_code = "<ul>" + "\n\n"
for item in seq:
html_code = html_code + "<li>" + item + "\n"
html_code = html_code + "\n" + "</ul>"
return html_code
|
Data (whether retrived from a file, database, etc) is usually retrived into a sequence. This function provides a quick way to present this information. I only made this function for one-dimensional sequences, because there would be no uniform way to do multi-dimensional sequences. If I were to make this function for multi-dimensional sequences, it would be unportable and wouldn't scale to every project..
Handle multidimensional lists using recursion. The function could handle multidimensional lists if recursion were used:
Recursion w/ indentation. You could also have it nicely format your recursion:
List Comprehensions are a natural here. A list comprehension may make the body clearer: