'Analyses the document to find the median line length.
percentage is a decimal number, 0 - 1 which is used to determine
how far in the list of line lengths to use. The list of line lengths is
ordered smallest to larged and does not include duplicates. 0.5 is the
median value.'

def line_length(self, percent):

    lengths = []
    for line in self.lines:
        if (len(line) > 0):
            lengths.append(len(line))
    if (not lengths):
        return 0
    lengths = list(set(lengths))
    total = sum(lengths)
    avg = (total / len(lengths))
    max_line = (avg * 2)
    lengths = sorted(lengths)
    for i in range((len(lengths) - 1), (-1), (-1)):
        if (lengths[i] > max_line):
            del lengths[i]
    if (percent > 1):
        percent = 1
    if (percent < 0):
        percent = 0
    index = (int((len(lengths) * percent)) - 1)
    return lengths[index]
