I have a list of elements, and I need to generate a bunch of these:
<div class="row">
<div class="row-element"> datapoint 1</div>
<div class="row-element"> datapoint 2</div>
<div class="row-element"> datapoint 3</div>
<div class="row-element"> datapoint 4</div>
</div>
.... # And so on
It gets tricky trying to do this. The list some_list
length can be odd or even too. Every div row should have at most four child row-elements.
for i,x in enumerate(some_list):
if i%4 == 0:
print '<div class="row">'
tmp = i+4
print '<div class="row-element">' + x + '</div>'
if tmp-1==i:
print '</div>'
This sort of works only if the list is evenly divisible by 4, and also it's really ugly code-wise.
How would I generate enclosing div tags for even and odd number elements cleanly in python?