Taks

mail@pastecode.io avatar
unknown
python
2 years ago
732 B
6
Indexable
Never
n = list(map(int,list('102087607280291102')))
k = int(11)
lenght = len(n) - k
n2 = []


# function to find the second max number in the list
def second_max(n):
    max1 = max(n)
    max2 = -1
    for i in n:
        if i != max1:
            if max2 == -1:
                max2 = i
            elif i > max2:
                max2 = i
    return max2
n3 = n[:]
for i in range(len(n)):
    print(n)
    print(n2)
    try:
        if len(n2) <= lenght and n.index(max(n)) <= lenght:
            n2.append(max(n))
            n = n[n.index(max(n))+1:]
        elif len(n2) <= lenght and n.index(max(n3)) >= lenght:
            n2.append(second_max(n))
            n = n[n.index(second_max(n))+1:]
    except:
        break



print(n2)