-def opentag(tag, block = 0, id = None, cl = None): # write html opening tag
- output = ""
- if (block):
- output += '\n'
- output += '<' + tag
- if (id != None):
- output += " id='" + id + "'"
- if (cl != None):
- output += " class='" + cl + "'"
- output += '>'
- if (block):
- output += '\n'
- return output
-
-def closetag(tag, block = 0): # write html closing tag
- if (block == 0):
- return "</" + tag + ">"
- else:
- return "\n</" + tag + ">\n"
-
-def tag(tag, block = 0, content = ""): # write html opening tag, content, and html closing tag
- o = opentag(tag, block)
- c = closetag(tag, block)
- return o + content + c
-
-def orderbyfreq(l): # order a list by the frequency of its elements and remove duplicates
- temp_l = l[:]
- l = list(set(l))
- l = [[i, temp_l.count(i)] for i in l] # add count of each element
- l.sort(key=lambda x:temp_l.count(x[0])) # sort by count
- l = [i[0] + ' (' + str(i[1]) + ')' for i in l] # put element and count into string
- l = l[::-1] # reverse
- return l
-