Build unordered list in HTML from a python list
Dave Angel
davea at ieee.org
Wed Jun 30 09:30:46 EDT 2010
Nico Grubert wrote:
> Use a stack?
>>
>> Whenever you start a new list, push the corresponding closing tag onto
>> a stack. Whenever your "indent level" decreases, pop the stack and
>> write out the closing tag you get.
>>
>> It's straightforward to use a python list as a stack.
>
> Thanks for the tip, Kushal.
> Do you have a short code example for me?
>
> Regards
> Nico
>
>
mylist = [3, 4, 5]
mylist.append[42]
print mylist 3,4,5,42
item = mylist.pop() returns the 42, removing it from the list
So, use append as a push, and pop without arguments as a pop. And use
len() to decide how big the list currently is.
DaveA
More information about the Python-list
mailing list