def bubble_sort(lst):
    swap = True
    while swap == True:
        swap = False
        for i in range(len(lst)-1):
            if lst[i] < lst[i+1]:
                lst[i], lst[i+1] = lst[i+1], lst[i]
                swap = True
    return lst

def top_k(lst, k):
    lst = bubble_sort(lst)
    return lst[:k]


def top_k(lst, k):
    return merge_sort(lst)[:k]

def merge_sort(lst):
    if len(lst) < 2:
        return lst
    mid = len(lst) // 2
    left = merge_sort(lst[:mid])
    right = merge_sort(lst[mid:])
    return merge(left, right)

def merge(left, right):
    results = []
    while left and right:
        if left[0] > right[0]:
            results.append(left.pop(0))
        else:
            results.append(right.pop(0))
    results.extend(left)
    results.extend(right)
    return results

Task: Top-K

Write a function top_k that accepts a list of integers as the input and returns the greatest
k number of values as a list, with its elements sorted in descending order. You may use
any sorting algorithm you wish, but you are not allowed to use sort and sorted.


def top_k(lst, k):

    sort = []

    while lst:

        largest = lst[0]

        for x in lst:

            if x > largest:

                largest = x

        lst.remove(largest)

        sort.append(largest)

    return sort[:k]


def top_k(lst, k):
    x = []
    for i in range(k):
        a = 0
        for ele in lst:
            if ele >= a:
                a = ele
        lst.remove(a)
        x.append(a)
    return x


def top_k(lst, k):
    def sort(lst):
        new = []
        while lst:
            greatest = lst[0]
            for i in lst:
                if i > greatest:
                    greatest = i
            lst.remove(greatest)
            new.append(greatest)
        return new
    return sort(lst)[:k]


def top_k(lst,k):
    nlst = []
    for x in range(k):
        b = max(lst)
        nlst.append(b)
        lst.remove(b)
    return nlst


def top_k(lst, k):
    product = []
    while k > 0:
        product += [max(lst)]
        k = k -1
        lst.remove(max(lst))
    return product


def top_k(lst, k):
	top_lst = []
	for i in range(0, k):
		top_lst += [max(lst)]
		lst.remove(max(lst))
	return top_lst


def top_k(lst, k):
    list = []
    while len(list) < k:
        a = max(lst)
        lst.remove(a)
        list.append(a)
    return list


def top_k(lst, k):
    count=0
    newlst=[]
    while lst:
        newlst+=[max(lst)]
        lst.remove(max(lst))
    for i in range(k):
        lst.append(newlst[i])
    return lst


def top_k(lst,k):
	if len(lst) == 0:
		return lst
	largest = 0
	newlist = []
	for i in range(k):
		for item in lst:
			if item >= largest:
				largest = item
		lst.remove(largest)
		newlist.append(largest)
		if len(lst) == 0:
			break
		largest = lst[0]
	return newlist


def top_k(lst, k):
    if k<=0:
        return []
    else:
        maxi=max(lst)
        length=len(lst)
        for i in range(length):
            if lst[i]==maxi:
                pos=i
        new_list=lst.copy()
        new_list.pop(pos)
        return [maxi]+top_k(new_list,k-1)


def top_k(lst, k):
	newlst = []
	while len(newlst) < k:
		newlst += (lst.pop(lst.index(max(lst))),)
	return newlst


def top_k(lst, k):
    af_sort = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        af_sort.append(biggest)
    return af_sort[0:k]


def top_k(lst, k):
    values = []
    while len(values) < k:
        greatest = lst[0]
        for item in lst:
            if item > greatest:
                greatest = item
        lst.remove(greatest)
        values.append(greatest)

    return values


def top_k(lst, k):
    for x in range(k+1):
        max = x
        for i in range(x, len(lst)):
            if lst[i] > lst[max]:
                max = i
        if x <= (len(lst) - 1):
            lst[max], lst[x] = lst[x], lst[max]
    new = lst[:k]
    return new


def top_k(lst, k):
    newlst = []
    while len(newlst)<k:
        maximum = lst[0]
        for i in lst:
            if i > maximum:
                maximum = i
        newlst.append(maximum)
        lst.remove(maximum)
    return newlst


def top_k(lst, k):
    result = []
    for i in range(k):
        result.append(max(lst))
        lst.remove(max(lst))
    return result


def top_k(lst, k):
	def sort_num(lst):
		for k in range(len(lst)-1):
			for i in range(k+1, len(lst)):
				if lst[k] < lst[i]:
					lst[k], lst[i] = lst[i], lst[k]
				else:
					continue
		return lst
	slst = sort_num(lst)
	return slst[:k]


def top_k(lst, k):
    n= []
    while lst:
        big = lst[0]
        for ele in lst:
            if ele>big:
                big = ele
        if len(n)==k:
            break
        else:
            n.append(big)
            lst.remove(big)
    return n

    pass


def top_k(lst, k):
    new, a = [], lst[0]
    while lst:
        for i in range(len(lst)):
            new.append(max(lst))
            lst.remove(max(lst))
    return new[:k]
    pass


def top_k(lst, k):
	new_lst = []
	cut_lst = []
	while lst:
		biggest = lst[0]
		for i in lst:
			if i > biggest:
				biggest = i
		lst.remove(biggest)
		new_lst.append(biggest)
	for i in range(k):
		cut_lst.append(new_lst[0])
		new_lst.pop(0)
	return cut_lst


def top_k(lst, k):
    new_lst = []
    while len(new_lst) < k:
        new_lst.append(max(lst))
        lst.remove(max(lst))
    return new_lst


def top_k(lst, k):
    final = []
    while len(final) != k:
        a = max(lst)
        final.append(a)
        lst.remove(a)
    return final


def top_k(lst, n):
    for j in range(len(lst)):
            maxi=lst[j]
            for k in range(j+1,len(lst)):
                if lst[k]>maxi:
                    maxi=lst[k]
                    lst[j],lst[k]=lst[k],lst[j]
            result=lst[0:n]
    return result


def top_k(lst, k):
    new_lst = []
    while len(new_lst) < k:
        maximum = max(lst)
        new_lst.append(maximum)
        lst.remove(maximum)

    return new_lst


def top_k(lst, k):
    product = []
    while k > 0:
        product += [max(lst)]
        k = k -1
        lst.remove(max(lst))
    return product


def top_k(lst, k):
    k=len(lst) if k>len(lst) else k
    l=[]
    while len(l)!=k:
        m=lst[0]
        for i in lst:
            if i>m:
                m=i
        l.append(m)
        lst.remove(m)
    return l


def top_k(lst, k):
    sorted_lst = []
    while lst:
        biggest = lst[0]
        for n in range(len(lst)):
            if lst[n] >= biggest:
                biggest = lst[n]
        lst.remove(biggest)
        sorted_lst.append(biggest)
    return sorted_lst[0:k]


def top_k(lst, k):
    swap = True
    while swap:
        swap = False
        for i in range(len(lst)-1):
            if lst[i] < lst[i+1]:
                lst[i], lst[i+1] = lst[i+1], lst[i]
                swap = True
    return lst[:k]
    pass


def top_k(lst, k):
    newlist = []
    while len(newlist) < k:
        newlist += [max(lst)]
        for i in range(len(lst)):
            if lst[i] == max(lst):
                break
        del lst[i]
    return newlist


def top_k(lst, k):
    for i in range(len(lst)-1):
        for j in range(i+1, len(lst)):
            if lst[i] < lst[j]:
                lst[i], lst[j] = lst[j], lst[i]
    result = []
    for i in range(k):
        result.append(lst[i])
    return result


def top_k(lst, k):
    new = []
    for i in range(k):
        largest = max(lst)
        new += [largest]
        lst.remove(largest)
    return new


def top_k(lst, k):
    sort = []
    i = 0
    while i < k:
        smallest = lst[0]
        for element in lst:
            if element > smallest:
                smallest = element
        lst.remove(smallest)
        sort.append(smallest)
        i += 1

    return sort


def top_k(lst, k):
    # Fill in your code here
    def sort(lst):
        sorted_list = []
        while lst:
            largest = lst[0]
            for element in lst:
                if largest < element:
                    largest = element
            lst.remove(largest)
            sorted_list.append(largest)
        return sorted_list
    return sort(lst)[:k]
    pass


def top_k(lst, k):
    new = []
    i = 1
    while i <= k:
        element = find_largest(lst)
        new.append(element)
        lst.remove(element)
        i = i+1
    return new

def find_largest(lst):
    largest = lst[0]
    for element in lst:
        if element > largest:
            largest = element
    return largest


def top_k(lst,k):
    n = len(lst)
    result = []
    while n !=0:
        test =[]
        for counter in range(n):
            test.append(lst[counter])
        first = max(test)
        for counter in range(n):
            if lst[counter] == first:
                result.append(lst.pop(counter))
                break
        n = len(lst)
    return result[:k]


def top_k(lst, k):
    result = []
    while lst:
      biggest = lst[0]
      for e in lst:
        if e > biggest:
            biggest = e
      result.append(biggest)
      lst.remove(biggest)
    return result[:k]


def top_k(lst,k):
    sort_list = []
    while lst:
        biggest = lst[0]
        for e in lst:
            if biggest < e:
                biggest = e
        lst.remove(biggest)
        sort_list.append(biggest)
    return sort_list[:k]


def top_k(lst, k):
    n = len(lst)
    new =[]
    for i in range(0,n):
        largest = max(lst)
        lst.remove(largest)
        new.append(largest)
    return new[:k]


def top_k(lst, k):

    while True:
        changed = False
        for i in range(len(lst)-1):
            if lst[i+1]>lst[i]:
                lst[i],lst[i+1] = lst[i+1], lst[i]
                changed = True
        if not changed:
            break

    while len(lst)>k:
        if len(lst)<=k:
            return lst
        else:
            lst.pop(k)

    return (lst)


def sort_list(lst):
    if len(lst) < 2:
        return lst
    for j in range(len(lst)-1):
        minimum = j
        for i in range(j+1, len(lst)):
            if lst[minimum] > lst[i]:
                minimum = i
        lst[j], lst[minimum] = lst[minimum], lst[j]
    lst.reverse()
    return lst

def top_k(lst, k):
    a = sort_list(lst)
    return a[0:k]


def top_k(lst, k):
    count = 0
    op = []
    while count < k:
        op += [max(lst)]
        lst.remove(max(lst))
        count += 1
    return op


def top_k(lst, k):
    a=[]
    while lst:
        for i in lst:
            a.append(max(lst))
            lst.remove(max(lst))
    return a[0:k]


def top_k(lst, k):
    newlist = []
    while len(newlist)<k:
        newlist.append(max(lst))
        lst.remove(max(lst))
    return newlist


def top_k(lst, k):
    for i in range(len(lst)):
        for j in range(i, len(lst)):
            if lst[j] > lst[i]:
                lst[i], lst[j] = lst[j], lst[i]
    return lst[:k]


def top_k(lst, k):
    new = []
    for i in range(k):
        top = max(lst)
        new.append(top)
        lst.remove(top)

    return new


def top_k(lst, k):
    values = []
    while len(values) < k:
        greatest = lst[0]
        for item in lst:
            if item > greatest:
                greatest = item
        lst.remove(greatest)
        values.append(greatest)

    return values


def top_k(lst, k):
    unsorted = lst
    result = []
    while True:
        if len(result) == k:
            break
        result += [max(unsorted),]
        unsorted.remove(max(unsorted))
    return result


def top_k(lst, k):
    if k == 0:
        return []
    if lst == []:
        return lst
    sort = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        sort.append(biggest)
        if len(sort) == k:
            return sort
        else:
            continue


def top_k(lst, k):
    new_lst = []
    for i in range(k):
        new_lst.append(max(lst))
        lst.remove(max(lst))
    return new_lst
    pass


def top_k(lst,k):
    a = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        a.append(biggest)
    return a[:k]


def top_k(lst, k):
    sort = []
    while lst:
        oldest = lst[0]
        for x in lst:
            if x > oldest:
                oldest = x
        lst.remove(oldest)
        sort.append(oldest)
    return sort[0:k]


def top_k(lst, k):
    if k<=0:
        return []
    else:
        maxi=max(lst)
        length=len(lst)
        for i in range(length):
            if lst[i]==maxi:
                pos=i
        new_list=lst.copy()
        new_list.pop(pos)
        return [maxi]+top_k(new_list,k-1)


def top_k(lst, k):
    def pos(seq,i):
        n = len(seq)
        for j in range(n):
            if seq[j] == i:
                return j
    def largest(seq):
        largest = seq[0]
        for i in seq:
            if i > largest:
                largest = i
        return pos(seq,largest)
    n_list =[]
    if k ==1:
        return [lst[largest(lst)]]
    elif lst == [] or k==0:
        return []
    else:
        z = lst.pop(largest(lst))
        n_list = [z]+ top_k(lst, k-1)
        return n_list

    # Fill in your code here
    pass


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for elem in lst:
            if elem > biggest:
                biggest = elem
        lst.remove(biggest)
        sort.append(biggest)
    return sort[:k]


def top_k(lst, k):
    # Fill in your code here
    a = lst
    sort = []
    while a:
        largest = a[0]
        for item in a:
            if item>largest:
                largest = item
        a.remove(largest)
        sort.append(largest)
    return(sort)[:k]


def top_k(lst, k):
    for j in range(len(lst)-1):
        for i in range(len(lst)-1):
            if lst[i] < lst[i+1]:
                lst[i], lst[i+1] = lst[i+1], lst[i]
    return lst[0:k]

    pass


def top_k(lst, k):
	result = []
	while lst:
		biggest = lst[0]
		for item in lst:
			if item > biggest:
				biggest = item
		lst.remove(biggest)
		result.append(biggest)
	return result[:k]


def top_k(lst, k):
    n = len(lst) - 1
    while n > 0:
        for i in range(n):
            if lst[i]> lst[i+1]:
                lst[i], lst[i+1] = lst[i+1], lst[i]
        n = n-1
    lst.reverse()
    return lst[:k]


def sort_descending(lst):
    new_lst = []
    while lst:
        largest = lst[0]
        for i in range(len(lst)):
            if lst[i] > largest:
                largest = lst[i]
        lst.remove(largest)
        new_lst.append(largest)
    return new_lst

def top_k(lst, k):
    lst = sort_descending(lst)
    return lst[:k]


def top_k(lst, k):
    results = []
    counter = 0
    while counter < k:
        for i in range(-len(lst),0):
            if lst[i] == max(lst):
                results.append(lst.pop(i))
                break
        counter += 1
    return results


def top_k(lst, k):
    # Fill in your code here
    data_list = lst
    new_list = []
    while data_list:
        minimum = data_list[0]  # arbitrary number in list
        for x in data_list:
            if x > minimum:
                minimum = x
        new_list.append(minimum)
        data_list.remove(minimum)
    return new_list[:k]


def top_k(lst, k):
    # Fill in your code here

    result = []
    while lst:
        minimum = lst[0]  # arbitrary number in list
        for x in lst:
            if x > minimum:
                minimum = x
        result.append(minimum)
        lst.remove(minimum)
    return result[:k]


def top_k(lst, k):
    for start in range(len(lst)):
        minimum = start
        for i in range(start,len(lst)):
            if lst[i] < lst[minimum]:
                minimum = i
        lst[start], lst[minimum] = lst[minimum], lst[start]
    lst.reverse()
    return lst[:k]


def top_k(lst, k):
    new, a = [], lst[0]
    while lst:
        for i in range(len(lst)):
            new.append(max(lst))
            lst.remove(max(lst))
    return new[:k]
    pass


def top_k(lst, k):
    swap = True
    while swap:
        swap = False
        for i in range(len(lst)-1):
            if lst[i] < lst[i+1]:
                lst[i], lst[i+1] = lst[i+1], lst[i]
                swap = True
    return lst[:k]


def top_k(lst, k):
	def sortedd(lst):
		for j in range(len(lst)-1):
			for i in range(len(lst)-1):
				if lst[i] < lst[i+1]:
					lst[i], lst[i+1] = lst[i+1], lst[i]
		return lst
	return sortedd(lst)[:k]


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        sort.append(largest)
    return sort[:k]


def top_k(lst, k):
    for j in range(len(lst)):
        for i in range(len(lst)-1):
            if lst[i]<lst[1+i]:
                lst[i], lst[i+1] = lst[i+1], lst[i]
    return lst[:k]


def top_k(lst, k):
    # Fill in your code here
    sort_lst = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        sort_lst.append(biggest)
    return sort_lst[:k]


def top_k(lst, k):
    res =[]
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest =element
        lst.remove(largest)
        res.append(largest)
    return res[:k]


def top_k(lst,k):
    sort = []

    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        sort.append(biggest)
    new_sort = []
    for i in range (k):
        new_sort += [sort[i]]
    return new_sort


def top_k(lst, k):
    new_lst=[]
    def bubble_sort(lst):
        swap = True
        while swap:
            swap = False
            for i in range(len(lst)-1):
                if lst[i]<lst[i+1]:
                    lst[i],lst[i+1]=lst[i+1],lst[i]
                    swap =True
        return lst
    sorted_lst = bubble_sort(lst)
    while k:
        new_lst.append(sorted_lst.pop(0))
        k-=1
    return new_lst


def top_k(lst, k):
    new=[]
    for i in range(k):
        biggest=lst[0]
        for element in lst:
            if element>biggest:
                biggest=element
        new.append(biggest)
        lst.remove(biggest)
    return new


def top_k(lst, k):
    result = []
    length=len(lst)
    while len(lst)>length-k:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        result.append(biggest)
        lst.remove(biggest)

    return result
    pass


def top_k(lst, k):
    #assumes not nested lists
    new = []
    count = 0
    while count < k:
        largest = lst[0]
        for ele in lst:
            if ele > largest:
                largest = ele
        lst.remove(largest)
        new.append(largest)
        count = count + 1
    return new


def top_k(lst, k):
    res = []
    while len(res) != k:
        elem = max(lst)
        lst.remove(elem)
        res.append(elem)
    return res


def biggest(lst):
    big=lst[0]
    for i in range (len(lst)):
        if lst[i]>big:
            big=lst[i]
        else:
            continue
    return big

def top_k(lst, k):
    l=len(lst)
    new_list=[]
    for i in range (l):
        new_list.append(biggest(lst))
        lst.remove(biggest(lst))
    return new_list[:k]


def top_k(lst, k):
    a=[]
    sort =[]
    while lst:
        biggest = lst[0]
        for i in lst:
            if (i)> biggest:
                biggest = i
        lst.remove(biggest)
        sort.append(biggest)
    for i in range(k):
        a = a + [sort[i],]
    return a
    pass


def top_k(lst, k):
    swap = True
    while swap:
        swap = False
        for i in range(len(lst)-1):
            if lst[i] < lst[i+1]:
                lst[i], lst[i+1] = lst[i+1], lst[i]
                swap = True
    #lst order done

    return lst[:k]


def top_k(lst, k):
    new_list = []
    while k > 0:
        new_list.append(max(lst))
        lst.remove(max(lst))
        k = k-1
    return new_list


def top_k(lst, k):
    count=0
    newlst=[]
    while lst:
        newlst+=[max(lst)]
        lst.remove(max(lst))
    for i in range(k):
        lst.append(newlst[i])
    return lst


def top_k(lst, k):
    # Fill in your code here
    sort = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        sort.append(biggest)
    return sort[:k]


def top_k(lst,k):
    def top(lst):
        s = []
        while lst:
            smallest = lst[0]
            for element in lst:
                if element>smallest:
                    smallest = element
            lst.remove(smallest)
            s.append(smallest)

        return s
    s = top(lst)
    return s[:k]


def top_k(lst, k):
    result = []
    for i in range(len(lst)):
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        result.append(largest)
    return result[:k]


def top_k(lst, k):
    new_list = []
    while k>0:
        new_list.append(max(lst))
        lst.remove(max(lst))
        k-=1
    return new_list


def top_k(lst, k):
	def merge_sort(lst):
		if len(lst) == 0 or len(lst) ==1:
		    	return lst
		mid = len(lst) // 2
		left = merge_sort(lst[:mid])
		right = merge_sort(lst[mid:])
		return merge(left, right)
	def merge(left, right):
		a = []
		while left and right:
			if right[0]<left[0] :
				a.append(left.pop(0))
			else:
				a.append(right.pop(0))
		a.extend(left)
		a.extend(right)
		return a
	return merge_sort(lst)[:k]


def top_k(lst, k):
    result = []
    for x in range(k):
        result.append(max(lst))
        lst.remove(max(lst))
    return result


def top_k(lst, k):
	counter = 0
	result = []
	while counter < k:
		result.append(max(lst))
		lst.remove(max(lst))
		counter = counter + 1
	return result


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for i in lst:
            if i > largest:
                largest = i
        sort.append(largest)
        lst.remove(largest)
    top = sort[:k]
    return top


def top_k(lst, k):
    new_list= selection_sort(lst)
    results= []
    for i in range(k):
        results.append(new_list.pop(0))
    return results

def selection_sort(lst):
    for idx in range(len(lst)):
        minimum=idx
        for i in range(len(lst)):
            if lst[i] < lst[minimum]:
                minimum=i
            lst[minimum], lst[idx]= lst[idx], lst[minimum]
    return lst


def top_k(lst, k):
    new = []
    while lst:
        largest = lst[0]
        for i in lst:
            if i > largest:
                largest = i
        new.append(largest)
        lst.remove(largest)
    if k > len(new):
        return new
    else:
        return new[:k]


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        sort.append(largest)
    return sort[:k]


def top_k(lst, k):
    for i in range(0,len(lst)-1):
            for j in range(i+1,len(lst)):
                if lst[i]<lst[j]:
                    lst[i],lst[j]=lst[j],lst[i]
    return lst[0:k]


def top_k(lst, k):
    list = []
    while len(list) < k:
        a = max(lst)
        lst.remove(a)
        list.append(a)
    return list


def top_k(lst, k):

    sort = []

    while lst:

        largest = lst[0]

        for x in lst:

            if x > largest:

                largest = x

        lst.remove(largest)

        sort.append(largest)

    return sort[:k]


def top_k(lst, k):
    lst = sort_descending(lst)
    return lst[:k]

def sort_descending(lst):
    for i in range(len(lst)-1):
        for j in range(i, len(lst)):
            if lst[j] > lst[i]:
                x = lst[i]
                lst[i] = lst[j]
                lst[j] = x
    return lst


def top_k(lst, k):
	res=[]
	while len(res)<k:
		res.append(max(lst))
		lst.remove(max(lst))
	return res


def top_k(lst, k):
    newlist = []
    while lst:
        biggest = lst[0]
        for i in lst:
            if i > biggest:
                biggest = i
            else:
                continue
        lst.remove(biggest)
        if len(newlist) == k:
            break
        else:
            newlist.append(biggest)
    return newlist


def top_k(lst, k):
    for start in range (len(lst) - 1):
        for i in range(start, len(lst)):
            if lst[i] > lst[start]:
                lst[i], lst[start] = lst[start], lst[i]
    return lst[:k]


def top_k(lst, k):
	sorted = []
	while lst:
		largest = lst[0]
		for i in lst:
			if i > largest:
				largest = i
		sorted.append(largest)
		lst.remove(largest)
	return sorted[:k]


def top_k(lst, k):
    # Fill in your code here
    sorted = []

    while lst:
        smallest = lst[0] # smallest has to exist within this step
        for i in lst:
            if i < smallest:
                smallest = i # take note: you must not reverse this step

        sorted.append(smallest)
        lst.remove(smallest)

    #ends the while loop, when lst has no elements
    # and every element is sorted into sorted
    sorted.reverse()

    return sorted[0:k]


def top_k(lst,k):
    result=[]
    while lst:
        minimum=lst[0]
        for i in lst:
            if i<minimum:
                minimum=i
        result.append(minimum)
        lst.remove(minimum)
    result=result[::-1]
    return result[:k]


def sort_list(lst):
    if len(lst) < 2:
        return lst
    for i in range(len(lst)-1):
        min = i
        for j in range(i+1, len(lst)):
            if lst[min] > lst[j]:
                min = j
        lst[i], lst[min] = lst[min], lst[i]
    lst.reverse()
    return lst
def top_k(lst, k):
    ans = sort_list(lst)
    return ans[0:k]# Fill in your code here


def top_k(lst, k):
    sort = []
    while lst:
        big = max(lst)
        sort.append(big)
        lst.remove(big)
    output = []
    for i in range(k):
        output.append(sort[i])
    return output


def order (lst):
	for i in range(len(lst)):
		for j in range(i+1, len(lst)):
			if lst[j] < lst[i]:
				lst[i], lst[j] = lst[j], lst[i]
	return lst

def top_k(lst, k):
	result = []
	a = order(lst)
	counter = 0
	while counter < k:
		result.append(a.pop())
		counter +=1
	return result


def top_k(lst, k):
    new = []
    ans = []
    for i in lst:
        index = 0
        for x in new:
            if i < x:
                index += 1
        new.insert(index, i)
    for i in range(k):
        ans.append(new[i])
    return ans


def top_k(lst, k):
    a=[]
    sort =[]
    while lst:
        biggest = lst[0]
        for i in lst:
            if (i)> biggest:
                biggest = i
        lst.remove(biggest)
        sort.append(biggest)
    for i in range(k):
        a = a + [sort[i],]
    return a
    pass


def top_k(lst, k):
    sotsot = []
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        sotsot.append(largest)
    return sotsot[:k]


def top_k(lst,k):
    nlst = []
    for x in range(k):
        b = max(lst)
        nlst.append(b)
        lst.remove(b)
    return nlst


def top_k(lst, k):
    a = lst.copy()
    b = lst.copy()
    lst.clear()
    for i in range(len(b)):
        lst.append(max(a))
        a.remove(max(a))
    lst = lst[:k]
    return lst# Fill in your code here
    pass


def top_k(lst, k):
    a=[]
    for i in range (0,k):
        a=a+[max(lst)]
        lst.remove(max(lst))

    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] > a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]

    return a


def merge_sort(lst):
    if len(lst) < 2:
        return lst
    mid = len(lst) // 2
    left = merge_sort(lst[:mid])
    right = merge_sort(lst[mid:])
    return merge(left, right)

def merge(left, right):
    results = []
    while left and right:
        if left[0] < right[0]:
            results.append(left.pop(0))
        else:
            results.append(right.pop(0))
    results.extend(left)
    results.extend(right)
    return results
def top_k(lst, k):
    result=merge_sort(lst)
    result.reverse()
    answer=[]
    for i in range(0,k):
        answer=answer+[result[i]]
    return answer
    pass


def top_k(lst, k):
    lst2 = []
    largest = lst[0]
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        lst2.append(largest)
    return lst2[0:k]


def top_k(lst, k):
    def sort_largest(lst):
        result = []
        while lst and k:
            largest = lst[0]
            index = 0
            for i in range(len(lst)):
                if lst[i] > largest:
                    index = i
                    largest = lst[i]
            result.append(largest)
            lst.remove(largest)
            if len(result) == k:
                break
        return result
    return sort_largest(lst)


def top_k(lst, k):
    new_lst = []
    while lst:
	    high = lst[0]
	    for i in lst:
		    if high < i:
			    high = i
	    new_lst.append(high)
	    lst.remove(high)
    return new_lst[:k]


def top_k(lst, k):
    result = []
    while lst:
        biggest = lst[0]
        for elem in lst:
            if elem > biggest:
                biggest = elem
        lst.remove(biggest)
        result.append(biggest)

    return result[:k]

    # Fill in your code here
    pass


def top_k(lst, k):
    while lst:
        maximum=[]
        for a in range(len(lst)):
            maximum.append(max(lst))
            lst.remove(max(lst))

    return maximum[0:k]


def top_k(lst, k):
    final = []
    while lst:
        biggest = lst[0]
        for i in lst:
            if i>biggest:
                biggest = i
        lst.remove(biggest)
        final.append(biggest)
    return final[:k]


def top_k(lst, k):
    lst2 = []

    while lst:
        lst2.append(max(lst))
        lst.remove(max(lst))
        for x in lst:
            if x in lst2:
                lst2.append(x)
                lst.remove(x)
    return lst2[:k]


def top_k(lst, k):
    for i in range(len(lst)):
        for j in range(len(lst) - 1):
            if lst[j] > lst[j + 1]:
                lst[j], lst[j + 1] = lst[j + 1], lst[j]
    lst.reverse()
    return lst[:k]
    pass


def top_k(lst, k):
    l = []
    if k > len(lst):
        return False
    elif k == 1:
        return lst
    else:
        while len(l) < k:
            a = max(lst)
            lst.remove(a)
            l.append(a)

        return l

    # Fill in your code here
    pass


def top_k(lst, k):
    newlst=[]
    while lst:
        largest=lst[0]
        for i in lst:
            if largest<i:
                largest=i
        newlst.append(largest)
        lst.remove(largest)
    return newlst[:k]


def top_k(lst, k):
    result = []
    while len(result) < k:
        result.append(lst.pop(lst.index(max(lst))))
    return result


def top_k(lst, k):
    new_lst = []
    counter = 1
    while counter <= k:
        highest = lst[0]  # arbitrary number in list
        for x in lst:
            if x > highest:
                highest = x
        new_lst.append(highest)
        lst.remove(highest)
        counter +=1

    return new_lst


def top_k(lst, k):
    new_lst = []
    while lst:
        largest = lst[0]
        for i in lst:
            if i > largest:
                largest = i
        lst.remove(largest)
        new_lst.append(largest)
    return new_lst[0:k]


def top_k(lst, k):
    num, result = max(lst), []
    while len(result) < k:
        if num in lst:
            result.append(num)
            lst.remove(num)
        elif num not in lst:
            num -= 1
            continue
    return result


def top_k(lst, k):
    x = []
    for i in range(k):
        a = 0
        for ele in lst:
            if ele >= a:
                a = ele
        lst.remove(a)
        x.append(a)
    return x


def top_k(lst, k):
    # Fill in your code here
    sort = []
    while lst:
        largest = lst[0]
        for i in range(len(lst)):
            if lst[i] > largest:
                largest = lst[i]
        sort.append(largest)
        lst.remove(largest)
    return sort[:k]


def sort(lst):
    if lst==[]:
        return []
    new_lst=[lst[0],]
    for x in lst[1:]:
        if x > new_lst[-1]:
            new_lst += [x,]
        else:
            count=0
            while count<len(new_lst):
                if x > new_lst[count]:
                    count+=1
                    continue
                else:
                    new_lst = new_lst[0:count]+[x,]+new_lst[count:]
                    break
    return new_lst[::-1]

def top_k(lst, k):
    return sort(lst)[0:k]


def top_k(lst, k):
    def sort(lst):
        if lst==[] or len(lst)==1:
            return lst
        else:
            temp=lst[0]
            count=0
            for i in range(len(lst)):
                if lst[i]>temp:
                    temp=lst[i]
                    count=i
            pop=lst.pop(count)
            return [temp,]+sort(lst)
    lst=sort(lst)
    return lst[:k]
    # Fill in your code here
    pass


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for i in lst:
            if i > largest:
                largest = i
        lst.remove(largest)
        sort.append(largest)
    return sort[:k]


def top_k(lst, k):
    def sort(lst2):
        holder = []
        if lst == [] :
            return []
        for x in lst :
            if holder == [] :
                holder = x
            elif x > holder :
                holder = x
        lst.remove(holder)
        return [holder]+ sort(lst2)
    counter = k
    final = []
    new_lst = sort(list)
    while counter > 0 :
        a = new_lst.pop(0)
        final.append(a)
        counter -= 1
    return final
    pass


def top_k(lst, k):
    new_list = []
    while k > 0:
        new_list.append(max(lst))
        lst.remove(max(lst))
        k = k-1
    return new_list


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for i in lst:
            if i>largest:
                largest = i
        lst.remove(largest)
        sort.append(largest)
    return sort[:k]


def top_k(lst, k):
    final = []
    while lst:
        biggest = lst[0]
        for i in lst:
            if i>biggest:
                biggest = i
        lst.remove(biggest)
        final.append(biggest)
    return final[:k]


def top_k(lst, k):
    sort = []
    sort_top_k = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        sort.append(biggest)

    if len(sort) < k:
        k = len(sort)
    for i in range(k):
        sort_top_k.append(sort[i])

    return sort_top_k


def top_k(lst, k):
    result=[]
    while k>0:
        result.append(max(lst))
        lst.remove(max(lst))
        k=k-1
    return result


def top_k(lst, k):
    # Fill in your code here
    sort_lst=sort(lst)
    return sort_lst[:k]

def sort(lst):
    sort=[]
    while lst:
        largest=lst[0]
        for elem in lst:
            if elem > largest:
                largest = elem
        lst.remove(largest)
        sort.append(largest)
    return sort


def top_k(lst, k):
    counter=0
    new_lst=[]
    while counter<k:
        maxi=max(lst)
        new_lst.append(maxi)
        lst.remove(maxi)
        counter+=1
    return new_lst


def top_k(lst,k): #k is the number of values in the lst
    lst2 = []
    for i in range(len(lst)):
        a = max(lst)
        lst2.append(a)
        lst.remove(a)
    return lst2[0:k]


def top_k(lst,k): #k is the number of values in the lst
    lst2 = []
    while lst:
        a = max(lst)
        lst2.append(a)
        lst.remove(a)
    return lst2[0:k]


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        sort.append(largest)
    return sort[0:k]


def top_k(lst, k):
    new = []
    ans = []
    for i in lst:
        index = 0
        for x in new:
            if i < x:
                index += 1
        new.insert(index, i)
    for i in range(k):
        ans.append(new[i])
    return ans


def top_k(lst, k):
    new_lst = []
    if k == 0 or lst == []:
        return []
    else:
        while k > 0:
            new_lst.append(max(lst))
            lst.remove(new_lst[-1])
            k -= 1
        return new_lst


def top_k(lst, k):
    result = []
    while lst:
        biggest = lst[0]
        for number in lst:
            if number > biggest:
                biggest = number
        lst.remove(biggest)
        result.append(biggest)
    return result[:k]


def top_k(lst, k):

    newlst = []
    for i in range(k):
        newlst.append(max(lst))
        lst.remove(max(lst))
    return newlst


def top_k(lst, k):
    a = mysort(lst)
    return a[:k]
    pass
def mysort(lst):
		counter = 0
		a = list(lst)
		while counter<len(lst):
			previous = a[0]
			for i in range(1,len(lst)):
				if a[i]>previous:
					a[i-1]=a[i]
					a[i]=previous
				else:
					previous = a[i]
			counter += 1
		return a


def top_k(lst,k):
	output = []
	for i in range(k):
		largest = max(lst)
		lst.remove(largest)
		output.append(largest)
	return output


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for e in lst:
            if e > largest:
                largest = e
        lst.remove(largest)
        sort.append(largest)
    return sort[:k]


def top_k(lst, k):
    new_lst = []
    counter = 1
    while counter <= k:
        highest = lst[0]  # arbitrary number in list
        for x in lst:
            if x > highest:
                highest = x
        new_lst.append(highest)
        lst.remove(highest)
        counter +=1

    return new_lst


def sort(lst):
	a = 0
	for i in range(len(lst)-1):
		if lst[i]<lst[i+1]:
			lst.insert(i,lst[i+1])
			lst.pop(i+2)
			a += 1
	if a == 0:
		return lst
	else:
		return sort(lst)

def top_k(lst, k):
    newlist = sort(lst)
    finish = []
    for i in range(k):
        finish.append(lst[i])
    return finish


def top_k(lst, k):
    new = []
    while lst:
        largest = lst[0]
        for a in lst:
            if a > largest:
                largest = a
        lst.remove(largest)
        new.append(largest)
    return new[0:k]


def top_k(lst, k):
    result = []
    while k >= 0:
        big = max(lst)
        result.append(big)
        lst.remove(big)
        k -= 1
    return result


def top_k(lst, k):
    lst_res = lst
    sort = []
    while lst_res:
        largest = lst_res[0]
        for elements in lst_res:
            if element > largest:
                largest = element
        lst_res.remove(largest)
        sort.append(largest)
    return sort[:k]


def top_k(lst, k):
    tmp = []
    while len(lst) > 0:
        tmp.append(max(lst))
        lst.remove(max(lst))
    return tmp[:5]


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if ele > biggest:
                biggest = ele

        lst.remove(element)
        sort.append(element)
        if len(sort)==k:
            break
    return sort


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element

        lst.remove(element)
        sort.append(element)
        if len(sort)==k:
            break
    return sort


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element

        lst.remove(biggest)
        sort.append(biggest)
        if len(sort)==k:
            break
    return sort


def top_k(lst, k):
    lst1 = []
    for i in lst:
        if i >= k:
            lst1.append(i)
    sort = []
    while lst1:
        biggest = lst[0]
        for element in lst1:
            if element > biggest:
                biggest = element
        lst1.remove(biggest)
        sort.append(biggest)
    return sort


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        sort.append(biggest)
    return sort[:k+1]


def top_k(lst, k):
    n = len(lst) - k
    counter = 0
    while counter < k:
        lst.remove(min(lst))
        counter = counter + 1
    sort_list = []
    while lst != []:
        sort_lst.append(max(lst))
        lst.remove(max(lst))
    return sort_list


def top_k(lst, k):
    n = len(lst) - k
    counter = 0
    while counter < k:
        lst.remove(min(lst))
        counter = counter + 1
    sort_list = []
    while lst != []:
        sort_list.append(max(lst))
        lst.remove(max(lst))
    return sort_list


def sort_age(lst):
        new=[]
        while lst !=[]:
            big=lst[0]
            for i in lst:
                if i[1]>big[1]:
                    big=i
            lst.remove(big)
            new.append(big)
        return new
def top_k(lst, k):
    return sort_age(lst)[:k]
    pass


def top_k(lst, k):

    if lst == []:
        return lst

    lower = []
    higher = []
    plist = []

    pivot = lst[0]
    for e in lst:
        if e < pivot:
            lower.append(e)
        if x == pivot:
            plist.append(e)
        if x > pivot:
            higher.append(e)
    sort_list = lower + plist + higher

    return sort_list[:k]


def top_k(lst, k):

    if lst == []:
        return lst

    lower = []
    higher = []
    plist = []

    pivot = lst[0]
    for e in lst:
        if e < pivot:
            lower.append(e)
        if x == pivot:
            plist.append(e)
        if x > pivot:
            higher.append(e)
    sort_list = higher + plist + lower

    return sort_list[:k]


def top_k(lst, k):

    if lst == []:
        return lst

    lower = []
    higher = []
    plist = []

    pivot = lst[0]
    for e in lst:
        if e < pivot:
            lower.append(e)
        if e == pivot:
            plist.append(e)
        if e > pivot:
            higher.append(e)
    sort_list = higher + plist + lower

    return sort_list[:k]


def top_k(lst, k):

    if lst == []:
        return lst

    lower = []
    higher = []
    plist = []

    pivot = lst[0]
    for e in lst:
        if e < pivot:
            lower.append(e)
        if e == pivot:
            plist.append(e)
        if e > pivot:
            higher.append(e)
    sort_list = lower + plist + higher
    sort_list = sort_list[::-1]

    return sort_list[:k]


def top_k(lst, k):

    if lst == []:
        return lst

    lower = []
    higher = []
    plist = []

    pivot = lst[0]
    for e in lst:
        if e < pivot:
            lower.append(e)
        if e == pivot:
            plist.append(e)
        if e > pivot:
            higher.append(e)
    sort_list = lower + plist + higher
    sort_list = sort_list[::-1]

    if k == len(lst):
        return sort_list[:k-1]
    elif k > len(lst):
        return sort_list
    else:
        return sort_list[:k]


def top_k(lst, k):
    result = []
    while lst:
        biggest = lst[0]
        for number in lst:
            if number > biggest:
                biggest = number
        lst.remove(biggest)
        result.append(oldest)
    return result[:k]


def top_k(lst, k):
    # Fill in your code here
    sort = []
    while lst: # a is not []
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        sort.append(largest)
    return sort[:k+1]


def top_k(lst, k):
    arranged = []
    while k>0:
        lst.remove(max(lst))
        arranged.append(max(lst))
        k -= 1
    return arranged
    pass


def top_k(lst, k):
    arranged = []
    while k > 0:
        lst.remove(max(lst))
        arranged.append(max(lst))
        k = k-1
    return arranged
    pass


def top_k(lst, k):
    r=[]
    for qwerty in range(0,k):
        biggest=lst[0]
        for k in lst:
            if biggest<k:
                biggest=k
        r.append[biggest]
        lst.remove[biggest]
    return r


def top_k(lst, k):
    rs=[]
    for qwerty in range(0,k):
        biggest=lst[0]
        for k in lst:
            if biggest<k:
                biggest=k
        rs.append[biggest]
        lst.remove[biggest]
    return r


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for i in lst[1:]:
            if i > biggest:
                oldest = i
        lst.remove(biggest)
        sort.append(biggest)

    n = 1
    sort_k = []
    while n <= k:
        sort_k.append(sort.pop[0])

    return sort_k


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for i in lst[1:]:
            if i > biggest:
                oldest = i
        lst.remove(biggest)
        sort.append(biggest)

    n = 1
    sort_k = []
    while n <= k:
        sort_k.append(sort.pop[0])
        n += 1

    return sort_k


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for i in lst[1:]:
            if i > biggest:
                oldest = i
        lst.remove(biggest)
        sort.append(biggest)

    n = 1
    sort_k = []
    while n <= k:
        sort_k.append(sort.pop(0))
        n += 1

    return sort_k


def top_k(lst, k):
    if lst==[]:
        return []
    sort=[]
    while lst:
        largest = lst[0]
        for i in lst:
            if i[1] > largest[1]:
                largest = i
        lst.remove(largest)
        sort.append(largest)
    return sort[:k]
    pass


def top_k(lst, k):
    sorted_lst = lst
    while sorted_lst:
        largest = sorted_lst[0]
        for element in sorted_lst:
            if element > largest:
                largest = element
        sorted_lst.remove(largest)
        sorted_lst.append(largest)
    return sorted_lst[:k-1]
    pass


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for i in lst:
            if i > largest:
                largest = i
        sort.append(i)
    return sort[:k-1]


def top_k(lst, k):
    sorted_list = []
    while lst:
        smallest = lst[0]
        for element in lst:
            if element < smallest:
                smallest = element
            lst.remove(element)
            sorted_list.append(element)
    return list.reverse(sorted_list)[:k-1]


def top_k(lst, k):
    sort, output = [], []
    while lst:
        largest = lst[0]
        for i in lst:
            if i > largest:
                largest = i
        lst.remove(largest)
        sort.append(largest)
    for j in sort:
        output.append(j)
        if len(output) == k:
            break
    return output


def top_k(lst, k):
    new_lst = []
    while lst:
        largest = lst[0]
        for numbers in lst:
            if numbers > largest:
                largest = numbers
        new_lst.append(lst.pop(largest))
    return new_lst[:k]


def top_k(lst, k):
    new_lst = []
    while lst:
        largest = lst[0]
        for numbers in lst:
            if numbers > largest:
                largest = numbers
        new_lst.append(numbers)
        lst.remove(numbers)
    return new_lst[:k]


def top_k(lst, k):
    final = []
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
            lst.remove(largest)
            final.append(largest)
        if len(final) == k:
            break
    return final


def top_k(lst, k):
    final = []
    while lst:
        element = max(lst)
        final += [element,]
        lst.remove(element)
        if len(final) == k:
            break
    return final


def top_k(lst, k):
    if lst == []:
        return []
    else:
        final = []
        while lst:
            element = max(lst)
            final += [element,]
            lst.remove(element)
            if len(final) == k:
                break
        return final


def top_k(lst, k):
    if lst == []:
        return []
    elif k == 0:
        return lst
    else:
        final = []
        while lst:
            element = max(lst)
            final += [element,]
            lst.remove(element)
            if len(final) == k:
                break
        return final


def top_k(lst, k):
    sort = []
    while lst:
        smallest = lst[0]
        for i in lst:
            if i<smallest:
                smallest = i
        lst.remove(smallest)
        sort.append(smallest)
    counter = k
    while counter !=len(lst):
        lst.pop()
        counter += 1
    return lst


def top_k(lst, k):
    i=0
    while i+1<len(lst):
        if lst[i]<lst[i+1]:
            lst.extend([i])
            lst.pop(i)
            i=0
        else:
            i+=1
    return lst[:4]


def top_k(lst, k):
    i=0
    while i+1<len(lst):
        if lst[i]<lst[i+1]:
            lst.extend([i])
            lst.pop(i)
            i=0
        else:
            i+=1
    return lst[:k+1]


def top_k(lst, k):
    i=0
    while i+1<len(lst):
        if lst[i]<lst[i+1]:
            lst.extend([i])
            lst.pop(i)
            i=0
        else:
            i+=1
    return lst[:k]


def top_k(lst, k):
    #top k in descending order
    sort = []
    x = len(lst)
    while x >= x-k:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        sort.append(largest)
    return sort


def top_k(lst, k):
    a=[]
    while lst:
        largest = lst[0]
        for i in lst:
            if i > largest:
                largest = i
                lst.remove(largest)
                a.append(largest)
    return a[:k]


def top_k(lst, k):
    af_sort = []
    while lst:
        biggest = lst[0]
        for element in a:
            if element > biggest:
                biggest = element
            lst.remove(biggest)
            af_sort.append(biggest)
    return af_sort[0:k]


def top_k(lst, k):
    newlst = []
    while len(newlst)<=k:
        maximum = lst[0]
        for i in lst:
            if i > maximum:
                maximum = i
        newlst.append(maximum)
        lst.remove(maximum)
    return newlst


def top_k(lst, k):
    new_list = []
    while len(new_list) < k:
        maximum = max(lst)
        new_lst.append(lst)
        lst.remove(maximum)

    return new_lst


def top_k(lst, k):
    sorted_lst = []
    while lst:
        for n in range(1, len(lst)):
            biggest = lst[0]
            if lst[n] > biggest:
                biggest = lst[n]
                lst.remove(biggest)
                sorted_lst.append(biggest)
    return sorted_lst[0:3]


def top_k(lst, k):
    sorted_lst = []
    while lst:
        for n in range(1, len(lst)):
            biggest = lst[0]
            if lst[n] >= biggest:
                biggest = lst[n]
                lst.remove(biggest)
                sorted_lst.append(biggest)
    return sorted_lst[0:k]


def top_k(lst, k):
    sorted_lst = []
    while lst:
        biggest = lst[0]
        for n in lst:
            if lst[n] >= biggest:
                biggest = lst[n]
        lst.remove(biggest)
        sorted_lst.append(biggest)
    return sorted_lst[0:k]


def top_k(lst, k):
    newlist = []
    while len(newlist) < k:
        newlist += [max(lst)]
        for i in range(len(lst)):
            if i == max(lst):
                print(i)
                break
        del lst[i]
    return newlist


def top_k(lst, k):
    a=[]
    while lst:
        biggest=lst[0]
        for i in lst:
            if i>biggest:
                biggest=i
                lst.remove(biggest)
                a.append(biggest)
    return a[0:k]


def top_k(lst, k):
    a = sort_list(lst)
    return a[0:k]


def top_k(lst, k):
    count = 0
    op = []
    big = lst[0]
    while count < k:
        op += max(lst)
        count += 1
    return op


def top_k(lst, k):
    count = 0
    op = []
    big = lst[0]
    while count < k:
        op += [max(lst)]
        count += 1
    return op


def top_k(lst, k):
    values = []
    greatest = lst[0]
    while len(values) < k:
        for item in lst:
            if item > greatest:
                greatest = item
        lst.remove(greatest)
        values.append(greatest)
        greatest = lst[0]
    return values


def top_k(lst, k):
    values = []
    while len(values) < k:
        for item in lst:
          greatest = lst[0]
          if item > greatest:
            greatest = item
        lst.remove(greatest)
        values.append(greatest)

    return values


def top_k(lst, k):
    sort = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        sort.append(biggest)
        if len(sort) == k:
            return sort
        else:
            continue


def top_k(lst, k):
    new_lst = []
    for i in range(k):
        new_lst.append(max(lst))
    return new_lst
    pass


def top_k(lst, k):
    new_lst = []
    for i in range(k):
        new_lst.append(lst.remove(max(lst)))
    return new_lst
    pass


def top_k(lst, k):
    new_lst = []
    while lst:
        biggest = lst[0]
        for x in lst:
            if x < lst[0]:
                biggest = x
        lst.remove(biggest)
        new_lst.append(biggest)
    return new_lst[0:k]


def top_k(lst, k):
    new_lst = []
    while lst:
        biggest = lst[0]
        for x in lst:
            if x > lst[0]:
                biggest = x
        lst.remove(biggest)
        new_lst.append(biggest)
    return new_lst[0:k]


def top_k(lst,k):
    a = []
    while lst:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        lst.remove(biggest)
        a.append(biggest)
    return a[:3]


def top_k(lst, k):
    if k<=0:
        return []
    else:
        maxi=max(lst)
        length=len(lst)
        for i in range(length):
            if lst[i]==maxi:
                pos=i
        new_list=lst.copy()
        new_list.pop(pos)
        return [maxi]+top_k(new_lst,k-1)


def top_k(lst, k):
    results = []
    counter = 0
    while counter < k:
        for i in range(-len(lst),-1):
            if lst[i] == max(lst):
                results.append(lst.pop(i))
                counter += 1
    return results
    pass


def top_k(lst, k):
    x = []
    for i in range(k-1):
        y = i
        for j in lst:
            if y < j:
                y = j
        x += y
    return x

    pass


def top_k(lst, k):
    # Fill in your code here
    a = lst
    sort = []
    while a:
        largest = a[0]
        for item in a:
            if item[1] >largest[1]:
                largest = item
        a.remove(largest)
        sort.append(largest)
    return(sort)[:k]


def top_k(lst, k):
    new = []
    while i in range(k-1):
        new.append(lst.pop(max(lst)))

    return new


def top_k(lst, k):
    new = []
    for i in range(k-1):
        new.append(lst.pop(max(lst)))

    return new


def top_k(lst, k):
    new = []
    while len(lst) > len(lst) - k:
        new.append(lst.pop(max(lst)))

    return new


def top_k(lst, k):
    new = []
    while len(lst) > len(lst) - k:
        new.append(lst.remove(max(lst)))

    return new


def top_k(lst, k):
    new = []
    while len(lst) >= len(lst) - k:
        top = max(lst)
        new.append(lst.remove(top))

    return new


def top_k(lst, k):
    results = []
    counter = 0
    while counter < k:
        for i in range(-len(lst),-1):
            if lst[i] == max(lst):
                results.append(lst.pop(i))
                counter += 1
    return results


def top_k(lst, k):
    results = []
    counter = 0
    while counter < k:
        for i in range(-len(lst),0):
            if lst[i] == max(lst):
                results.append(lst.pop(i))
                counter += 1
        continue
    return results


def top_k(lst, k):
    results = []
    counter = 0
    while counter < k:
        for i in range(-len(lst),0):
            if lst[i] == max(lst):
                results.append(lst.pop(i))
                counter += 1
    return results


def top_k(lst, k):
    new = []
    while len(lst) >= len(lst) - k:
        top = max(lst)
        new.append(top)
        lst.remove(top)

    return new


def top_k(lst, k):
    new = []
    while len(lst) > len(lst) - k:
        top = max(lst)
        new.append(top)
        lst.remove(top)

    return new


def top_k(lst, k):
    # Fill in your code here

    result = []
    while lst:
        minimum = lst[0]  # arbitrary number in list
        for x in lst:
            if x > minimum:
                minimum = x
        result.append(minimum)
        lst.remove(minimum)
    return lst[:k]


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
                lst.remove(largest)
                sort.append(largest)
    return sort[:k]


def top_k(lst, k):
    # Fill in your code here
    sort_lst = []
    while lst: # a is not []
        smallest = lst[0]
        for element in lst:
            if element < smallest:
                smallest = element
        lst.remove(smallest)
        sort_lst.append(smallest)
    return sort_lst[:k]


def top_k(lst, k):
    sotsot = []
    while len(sotsot) <=k:
        sotsot.append(max(lst))
        lst.remove(max(lst)) #wont return u any value just modified the list only.
    return sotsot


def top_k(lst, k):
    sotsot = []
    while lst:
        while len(sotsot) <=k:
            sotsot.append(max(lst))
            lst.remove(max(lst)) #wont return u any value just modified the list only.
        return sotsot


def top_k(lst, k):
    sotsot = []
    while lst:
        while len(sotsot)<=k :
            sotsot.append(max(lst))
            lst.remove(max(lst)) #wont return u any value just modified the list only.
        return sotsot


def top_k(lst, k):
    result = []
    for i in range(len(lst)):
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        result.append(largest)
    return lst[:k]


def top_k(lst, k):
    new_list = []
    for i in lst:
        if k==0:
            break
        new_list+=max(lst)
        k-1
    return lst
    pass


def top_k(lst, k):
    result = []

    while len(lst)>len(lst)-k:
        biggest = lst[0]
        for element in lst:
            if element > biggest:
                biggest = element
        result.append(biggest)
        lst.remove(biggest)

    return result
    pass


def top_k(lst, k):
    list = []
    while len(list) < k:
        a = max(lst)
        lst.remove(a)
        new.append(a)
    return list


def top_k(lst, k):
    list = []
    while len(lst) < k:
        a = max(lst)
        lst.remove(a)
        new.append(a)
    return list


def top_k(lst, k):
    lst = sort_descending(lst)
    return lst[:k-1]

def sort_descending(lst):
    for i in range(len(lst)-1):
        for j in range(i, len(lst)):
            if lst[j][1] > lst[i][1]:
                x = lst[i]
                lst[i] = lst[j]
                lst[j] = x
    return lst


def top_k(lst, k):
    newlist = []
    while lst:
        biggest = lst[0]
        for i in lst:
            if i > biggest:
                biggest = i
            else:
                continue
        lst.remove(biggest)
        if len(newlist) == k:
            break
        else:
            newlist.append(biggest)
        return newlist


def top_k(lst, k):
    sort = []
    while lst:
        big = max(lst)
        sort.append(big)
        lst.remove(big)

    output = [n for n in lst if lst.index(n) < k]
    return output


def top_k(lst, k):
    lst2 = []
    max = lst[0]
    for i in lst:
        if i > max:
            max = i
        while len(lst2) != k:
            lst2.append(max)
    return lst2


def top_k(lst, k):
    lst2 = []
    max = lst[0]
    for i in lst:
        if i > max:
            max = i
        lst.pop(max)
        while len(lst2) != k:
            lst2.append(max)
    return lst2


def top_k(lst, k):
    result = []
    while lst:
        biggest = lst[0]
        for elem in lst:
            if elem > biggest:
                biggest = elem
        lst.remove(biggest)
        result.append(biggest)

    return result[:3]

    # Fill in your code here
    pass


def top_k(lst, k):
    for i in range(len(lst)):
        for j in range(len(lst) - 1):
            if lst[j] > lst[j + 1]:
                lst[j] = lst [j + 1]
                lst[j + 1] = lst[j]
    lst.reverse()
    return lst[:k]
    pass


def top_k(lst, k):
    for i in range(len(lst)):
        for j in range(len(lst) - 1):
            if lst[j] > lst[j + 1]:
                lst[j] = lst[j + 1]
                lst[j + 1] = lst[j]
    lst.reverse()
    return lst[:k]
    pass


def top_k(lst, k):
    for i in range(len(lst)-1):
        if lst[i]<lst[i+1]:
            lst[i],lst[i+1]=lst[i+1],lst[i]
    return lst[:k]


def top_k(lst, k):
    # Fill in your code here
    sort = []
    while lst:
        largest = lst[0]
        for i in range(len(lst)):
            if lst[i] > largest:
                largest = lst[i]
        sort.append(largest)
        lst.remove(largest)
    return sort[:k + 1]


def top_k(lst, k):
    l = []
    if k > len(lst):
        return False
    elif k == 1:
        return lst
    else:
        a = max(lst)
        lst.remove(a)
        l.append(a)
        return top_k(lst, k-1)

    # Fill in your code here
    pass


def top_k(lst, k):
    l = []
    if k > len(lst):
        return False
    elif k == 1:
        return lst
    else:
        a = max(lst)
        lst.remove(a)
        l.append(a)
        top_k(lst, k-1)
        return l

    # Fill in your code here
    pass


def top_k(lst, k):
    l = []
    if k > len(lst):
        return False
    elif k == 1:
        return lst
    else:
        while len(l) <= k:
            a = max(lst)
            lst.remove(a)
            l.append(a)

        return l

    # Fill in your code here
    pass


def top_k(lst, k):
    # Fill in your code here
    sort=sort(lst)
    return sort[:k]

def sort(lst):
    sort=[]
    while lst:
        largest=lst[0]
        for elem in lst:
            if elem > largest:
                largest = elem
        lst.remove(largest)
        sort.append(largest)
    return sort


def top_k(lst, k):
    counter=0
    new_lst=[]
    while counter<k:
        new_lst.append(lst.remove(max(lst)))


def top_k(lst, k):
    counter=0
    new_lst=[]
    while counter<k:
        maxi=max(lst)
        new_lst.append(maxi)
        lst.remove(maxi)


def top_k(lst, k):
    counter=0
    new_lst=[]
    while counter<k:
        maxi=max(lst)
        new_lst.append(maxi)
        lst.remove(maxi)
        counter+=1


def top_k(lst, k):
    sort = []
    while lst:
        largest = lst[0]
        for element in lst:
            if element > largest:
                largest = element
        lst.remove(largest)
        sort.append(largest)
    return sort[0:3]


def top_k(lst, k):
    new = []
    lst.sort()
    for i in range(k-1):
        new.append(lst[i])
    return new


def top_k(lst, k):

    newlst = []
    for i in range(k+1):
        newlst.append(max(lst))
        lst.remove(max(lst))
    return newlst


def top_k(lst, k):
    new_lst = []
    counter = 0
    while counter <= k:
        highest = lst[0]  # arbitrary number in list
        for x in lst:
            if x > highest:
                highest = x
        new_lst.append(highest)
        lst.remove(highest)
        counter +=1

    return new_lst


# Reasons why the codes do not work

wrong_05_019.py

Instruction of line 4 and instruction of line 5 should be swapped (swapped lines).

wrong_05_020.py

Instruction of line 4 and instruction of line 5 should be swapped (swapped lines).

wrong_05_040.py

Wtf is that solution

wrong_5_46.py

Variable misuse, and variable has the wrong name (typo).

wrong_5_052.py

Function sort_list is not defined

wrong_5_066.py

The "[1]" is uncessary, must be removed

wrong_084.md

"+=" operation should be replaced by the append operation (misconception about what the += can do).
line 7, k-1, missing the assignment

wrong_086.py

variable misuse, at line 6, the list to which we append should be "list" not a

wrong_5_087.py

use of wrong variable, at the guard, the lenght of the list checked should be "list" not lst

wrong_5_096.py

strategy: sorting the list then returning the first elements
however, the sorting part is not working at all.

wrong_5_101.py

Perhaps there is a naming collision there

wrong_5_103.py

The student forgot to increase the value of the counter, reasulting in an infinite loop
so here, a full line is missing.

wrong_5_106.py

Strategy: sort the list then return a new list which contains different parts

## Notes to myself

I believe it is interesting to see how there are different "steps", which define a strategy for solving a problem. The, each strategy can have different approaches. I define the approach here as being the the specific implementation used in each step for obtaining what is requested.

Now, I have the question: how can we automatically delimitate the code such that the blocks correspond to one step of the problem solving step.


def sort_age(lst):
        new=[]
        while lst !=[]:
            big=lst[0]
            for i in lst:
                if i[1]>big[1]:
                    big=i
            lst.remove(big)
            new.append(big)
        return new
def top_k(lst, k):
    return sort_age(lst)[:k]
    pass


def top_k(lst, k):
    arranged = []
    while k>0:
        lst.remove(max(lst))
        arranged.append(max(lst))
        k -= 1
    return arranged
    pass


def top_k(lst, k):
    arranged = []
    while k > 0:
        lst.remove(max(lst))
        arranged.append(max(lst))
        k = k-1
    return arranged
    pass


def top_k(lst, k):
    i=0
    while i+1<len(lst):
        if lst[i]<lst[i+1]:
            lst.extend([i])
            lst.pop(i)
            i=0
        else:
            i+=1
    return lst[:k+1]


def top_k(lst, k):
    new_list = []
    while len(new_list) < k:
        maximum = max(lst)
        new_lst.append(lst)
        lst.remove(maximum)

    return new_lst


def top_k(lst, k):
    a = sort_list(lst)
    return a[0:k]


def top_k(lst, k):
    # Fill in your code here
    a = lst
    sort = []
    while a:
        largest = a[0]
        for item in a:
            if item[1] >largest[1]:
                largest = item
        a.remove(largest)
        sort.append(largest)
    return(sort)[:k]


def top_k(lst, k):
    new_list = []
    for i in lst:
        if k==0:
            break
        new_list+=max(lst)
        k-1
    return lst
    pass


def top_k(lst, k):
    list = []
    while len(list) < k:
        a = max(lst)
        lst.remove(a)
        new.append(a)
    return list


def top_k(lst, k):
    list = []
    while len(lst) < k:
        a = max(lst)
        lst.remove(a)
        new.append(a)
    return list


def top_k(lst, k):
    lst = sort_descending(lst)
    return lst[:k-1]

def sort_descending(lst):
    for i in range(len(lst)-1):
        for j in range(i, len(lst)):
            if lst[j][1] > lst[i][1]:
                x = lst[i]
                lst[i] = lst[j]
                lst[j] = x
    return lst


def top_k(lst, k):
    for i in range(len(lst)-1):
        if lst[i]<lst[i+1]:
            lst[i],lst[i+1]=lst[i+1],lst[i]
    return lst[:k]


def top_k(lst, k):
    # Fill in your code here
    sort=sort(lst)
    return sort[:k]

def sort(lst):
    sort=[]
    while lst:
        largest=lst[0]
        for elem in lst:
            if elem > largest:
                largest = elem
        lst.remove(largest)
        sort.append(largest)
    return sort


def top_k(lst, k):
    counter=0
    new_lst=[]
    while counter<k:
        maxi=max(lst)
        new_lst.append(maxi)
        lst.remove(maxi)


def top_k(lst, k):
    new = []
    lst.sort()
    for i in range(k-1):
        new.append(lst[i])
    return new