id
stringlengths
35
39
content
stringlengths
44
3.85k
max_stars_repo_path
stringlengths
52
57
refactory_data_question_5_correct_5_015
def top_k(lst, k): result = [] while k > 0: big = max(lst) result.append(big) lst.remove(big) k -= 1 return result
./refactory/data/question_5/code/correct/correct_5_015.py
refactory_data_question_5_correct_5_253
def top_k(lst, k): product = [] while k > 0: product += [max(lst)] k = k -1 lst.remove(max(lst)) return product
./refactory/data/question_5/code/correct/correct_5_253.py
refactory_data_question_5_correct_5_297
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
./refactory/data/question_5/code/correct/correct_5_297.py
refactory_data_question_5_correct_5_293
def top_k(lst, k): new = [] for i in range(k): top = max(lst) new.append(top) lst.remove(top) return new
./refactory/data/question_5/code/correct/correct_5_293.py
refactory_data_question_5_correct_5_054
def top_k(lst, k): answer = [] a = lst[0] while lst: for i in range(len(lst)): answer.append(max(lst)) lst.remove(max(lst)) return answer[:k]
./refactory/data/question_5/code/correct/correct_5_054.py
refactory_data_question_5_correct_5_383
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
./refactory/data/question_5/code/correct/correct_5_383.py
refactory_data_question_5_correct_5_324
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
./refactory/data/question_5/code/correct/correct_5_324.py
refactory_data_question_5_correct_5_121
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]
./refactory/data/question_5/code/correct/correct_5_121.py
refactory_data_question_5_correct_5_363
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
./refactory/data/question_5/code/correct/correct_5_363.py
refactory_data_question_5_correct_5_154
def top_k(lst, k): def merge_lists(left,right): new = [] while left and right: if left[0] >= right[0]: new.append(left.pop(0)) else: new.append(right.pop(0)) new.extend(left) new.extend(right) return new def binary_sort(lst): if len(lst) <2: return lst mid = len(lst)//2 left = binary_sort(lst[:mid]) right = binary_sort(lst[mid:]) return merge_lists(left,right) new = binary_sort(lst) return new[:k]
./refactory/data/question_5/code/correct/correct_5_154.py
refactory_data_question_5_correct_5_334
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]
./refactory/data/question_5/code/correct/correct_5_334.py
refactory_data_question_5_correct_5_394
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
./refactory/data/question_5/code/correct/correct_5_394.py
refactory_data_question_5_correct_5_036
def top_k(lst, k): if lst == [] or k == 0: return [] else: final = [] while lst: element = max(lst) final += [element,] lst.remove(element) if len(final) == k: break return final
./refactory/data/question_5/code/correct/correct_5_036.py
refactory_data_question_5_correct_5_195
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]
./refactory/data/question_5/code/correct/correct_5_195.py
refactory_data_question_5_correct_5_272
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
./refactory/data/question_5/code/correct/correct_5_272.py
refactory_data_question_5_correct_5_006
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]
./refactory/data/question_5/code/correct/correct_5_006.py
refactory_data_question_5_correct_5_397
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]
./refactory/data/question_5/code/correct/correct_5_397.py
refactory_data_question_5_correct_5_219
def top_k(lst, k): i=0 while i+1<len(lst): if lst[i]<lst[i+1]: lst.extend([lst[i]]) lst.pop(i) i=0 else: i+=1 return lst[:k]
./refactory/data/question_5/code/correct/correct_5_219.py
refactory_data_question_5_correct_5_069
def top_k(lst, k): sort=[] for i in range (k): biggest=max(lst) lst.remove(biggest) sort.append(biggest) return sort
./refactory/data/question_5/code/correct/correct_5_069.py
refactory_data_question_5_correct_5_047
def top_k(lst, k): new_list = [] while lst: maximum = lst[0] for i in lst: if i > maximum: maximum = i new_list.append(maximum) lst.remove(maximum) new_list_2 = [] counter = 0 for i in new_list: if counter < k: new_list_2.append(new_list[counter]) counter = counter + 1 return new_list_2
./refactory/data/question_5/code/correct/correct_5_047.py
refactory_data_question_5_correct_5_295
def top_k(lst, k): unsorted = lst result = [] while True: if len(result) == k: break result += [max(unsorted),] unsorted.remove(max(unsorted)) return result
./refactory/data/question_5/code/correct/correct_5_295.py
refactory_data_question_5_correct_5_337
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]
./refactory/data/question_5/code/correct/correct_5_337.py
refactory_data_question_5_correct_5_194
def top_k(lst, k): new_list = [] while lst: maximum = lst[0] for i in lst: if i > maximum: maximum = i new_list.append(maximum) lst.remove(maximum) new_list_2 = [] counter = 0 for i in new_list: if counter < k: new_list_2.append(new_list[counter]) counter = counter + 1 return new_list_2
./refactory/data/question_5/code/correct/correct_5_194.py
refactory_data_question_5_correct_5_287
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)
./refactory/data/question_5/code/correct/correct_5_287.py
refactory_data_question_5_correct_5_256
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
./refactory/data/question_5/code/correct/correct_5_256.py
refactory_data_question_5_correct_5_147
def top_k(lst, k): sort = [] while lst: biggest = lst[0] for i in lst[1:]: if i > biggest: biggest = 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
./refactory/data/question_5/code/correct/correct_5_147.py
refactory_data_question_5_correct_5_392
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]
./refactory/data/question_5/code/correct/correct_5_392.py
refactory_data_question_5_correct_5_339
def top_k(lst, k): counter = 0 result = [] while counter < k: result.append(max(lst)) lst.remove(max(lst)) counter = counter + 1 return result
./refactory/data/question_5/code/correct/correct_5_339.py
refactory_data_question_5_correct_5_125
def top_k(lst, k): arranged = [] while k > 0: arranged.append(max(lst)) lst.remove(max(lst)) k = k-1 return arranged pass
./refactory/data/question_5/code/correct/correct_5_125.py
refactory_data_question_5_correct_5_046
def top_k(lst, k): tmp = [] while len(lst) > 0: tmp.append(max(lst)) lst.remove(max(lst)) return tmp[:k]
./refactory/data/question_5/code/correct/correct_5_046.py
refactory_data_question_5_correct_5_091
def top_k(lst, k): sorted_list = [] while lst: smallest = lst[0] for element in lst: if element < smallest: smallest = element lst.remove(smallest) sorted_list.append(smallest) final = sorted_list[::-1] return final[:k]
./refactory/data/question_5/code/correct/correct_5_091.py
refactory_data_question_5_correct_5_245
def top_k(lst,k): sort = [] while lst: largest = lst[0] for element in lst: if largest < element: largest = element lst.remove(largest) sort.append(largest) return sort[0:k]
./refactory/data/question_5/code/correct/correct_5_245.py
refactory_data_question_5_correct_5_370
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
./refactory/data/question_5/code/correct/correct_5_370.py
refactory_data_question_5_correct_5_051
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]
./refactory/data/question_5/code/correct/correct_5_051.py
refactory_data_question_5_correct_5_172
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
./refactory/data/question_5/code/correct/correct_5_172.py
refactory_data_question_5_correct_5_345
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
./refactory/data/question_5/code/correct/correct_5_345.py
refactory_data_question_5_correct_5_229
def top_k(lst,k): def selection_sort(lst): srt = [] while lst: smallest = lst[0] for elem in lst: if elem < smallest: smallest = elem lst.remove(smallest) srt.append(smallest) return srt return selection_sort(lst)[-1:-k-1:-1]
./refactory/data/question_5/code/correct/correct_5_229.py
refactory_data_question_5_correct_5_309
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
./refactory/data/question_5/code/correct/correct_5_309.py
refactory_data_question_5_correct_5_367
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
./refactory/data/question_5/code/correct/correct_5_367.py
refactory_data_question_5_correct_5_205
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]
./refactory/data/question_5/code/correct/correct_5_205.py
refactory_data_question_5_correct_5_282
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
./refactory/data/question_5/code/correct/correct_5_282.py
refactory_data_question_5_correct_5_053
def top_k(lst, num): def insertion_sort(lst): for i in range(len(lst)): if i == 0: continue else: while i > 0: if lst[i] < lst[i-1]: lst[i], lst[i-1] = lst[i-1], lst[i] i -= 1 else: i = 0 insertion_sort(lst) lst.reverse() score, result = -1, [] for i in lst: if i == score: result += (i,) elif len(result) >= num: break else: result += (i,) score = i return result
./refactory/data/question_5/code/correct/correct_5_053.py
refactory_data_question_5_correct_5_210
def top_k(lst, k): result=[] for i in range(0,k): max=lst[0] for j in lst: if j>max: max=j result.append(max) lst.remove(max) return result# Fill in your code here pass
./refactory/data/question_5/code/correct/correct_5_210.py
refactory_data_question_5_correct_5_316
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]
./refactory/data/question_5/code/correct/correct_5_316.py
refactory_data_question_5_correct_5_300
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)
./refactory/data/question_5/code/correct/correct_5_300.py
refactory_data_question_5_correct_5_284
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]
./refactory/data/question_5/code/correct/correct_5_284.py
refactory_data_question_5_correct_5_057
def top_k(lst, k): sort = [] while lst: biggest = lst[0] for i in lst[1:]: if i > biggest: biggest = 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
./refactory/data/question_5/code/correct/correct_5_057.py
refactory_data_question_5_correct_5_254
def top_k(lst, k): top_lst = [] for i in range(0, k): top_lst += [max(lst)] lst.remove(max(lst)) return top_lst
./refactory/data/question_5/code/correct/correct_5_254.py
refactory_data_question_5_correct_5_105
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]
./refactory/data/question_5/code/correct/correct_5_105.py
refactory_data_question_5_correct_5_102
def top_k(lst, k): newlist = [] counter = k while counter > 0: biggest = lst[0] for i in lst[1:]: if biggest > i: continue else: biggest = i continue newlist += [biggest] counter -= 1 lst.remove(biggest) return newlist
./refactory/data/question_5/code/correct/correct_5_102.py
refactory_data_question_5_correct_5_058
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
./refactory/data/question_5/code/correct/correct_5_058.py
refactory_data_question_5_correct_5_371
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]
./refactory/data/question_5/code/correct/correct_5_371.py
refactory_data_question_5_correct_5_417
def top_k(lst, k): result=[] while k>0: result.append(max(lst)) lst.remove(max(lst)) k=k-1 return result
./refactory/data/question_5/code/correct/correct_5_417.py
refactory_data_question_5_correct_5_085
def top_k(lst, k): sorted_list = [] biggest = [] while lst: largest = 0 for i in lst: if i >= largest: largest = i lst.remove(largest) sorted_list.append(largest) # from biggest to smallest for j in range (k): biggest.append(sorted_list[j]) return biggest pass
./refactory/data/question_5/code/correct/correct_5_085.py
refactory_data_question_5_correct_5_382
def top_k(lst, k): result = [] while len(result) < k: result.append(lst.pop(lst.index(max(lst)))) return result
./refactory/data/question_5/code/correct/correct_5_382.py
refactory_data_question_5_correct_5_376
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]
./refactory/data/question_5/code/correct/correct_5_376.py
refactory_data_question_5_correct_5_150
def top_k(lst, k): def merge_sort(lst): if len(lst) < 2: # Base case! return lst mid = len(lst) // 2 left = merge_sort(lst[:mid]) #sort left right = merge_sort(lst[mid:]) #sort right 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 lst = merge_sort(lst) return lst[:k]
./refactory/data/question_5/code/correct/correct_5_150.py
refactory_data_question_5_correct_5_109
def top_k(lst, k): def sort(lst): new_lst=[] while lst: bigger=lst[0] for i in lst: if i>=bigger: bigger=i lst.remove(bigger) new_lst.append(bigger) return new_lst sorted_lst=sort(lst) return sorted_lst[:k]
./refactory/data/question_5/code/correct/correct_5_109.py
refactory_data_question_5_correct_5_327
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]
./refactory/data/question_5/code/correct/correct_5_327.py
refactory_data_question_5_correct_5_414
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]
./refactory/data/question_5/code/correct/correct_5_414.py
refactory_data_question_5_correct_5_409
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]
./refactory/data/question_5/code/correct/correct_5_409.py
refactory_data_question_5_correct_5_399
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
./refactory/data/question_5/code/correct/correct_5_399.py
refactory_data_question_5_correct_5_357
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]
./refactory/data/question_5/code/correct/correct_5_357.py
refactory_data_question_5_correct_5_175
def sort_no(lst): new = [] while lst: Max = max(lst,key = lambda x : x) new.append(Max) lst.remove(Max) return new def top_k(lst, k): Sorted = sort_no(lst) return Sorted[0:k]
./refactory/data/question_5/code/correct/correct_5_175.py
refactory_data_question_5_correct_5_031
def top_k(lst,k): sort = [] while lst: largest = lst[0] for element in lst: if largest < element: largest = element lst.remove(largest) sort.append(largest) return sort[0:k]
./refactory/data/question_5/code/correct/correct_5_031.py
refactory_data_question_5_correct_5_141
def top_k(lst,k): def sort_numbers(lst): result=[] def lame(lst): if lst==[]: return result result.append(max(lst)) lst.remove(max(lst)) return lame(lst) return lame(lst) return sort_numbers(lst)[:k]
./refactory/data/question_5/code/correct/correct_5_141.py
refactory_data_question_5_correct_5_146
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]
./refactory/data/question_5/code/correct/correct_5_146.py
refactory_data_question_5_correct_5_239
def top_k(lst, k): for i, e in enumerate(lst): mx = max(range(i,len(lst)), key= lambda x: lst[x]) lst[i], lst[mx] = lst[mx], e return lst[:k]
./refactory/data/question_5/code/correct/correct_5_239.py
refactory_data_question_5_correct_5_395
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]
./refactory/data/question_5/code/correct/correct_5_395.py
refactory_data_question_5_correct_5_342
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
./refactory/data/question_5/code/correct/correct_5_342.py
refactory_data_question_5_correct_5_302
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]
./refactory/data/question_5/code/correct/correct_5_302.py
refactory_data_question_5_correct_5_159
def top_k(lst, k): lst=sort_list(lst) while len(lst)>k: lst.pop(-1) return lst def sort_list(lst): sort=[] while lst: largest=lst[0] for i in lst: if i>largest: largest=i lst.remove(largest) #1.indentation: under while loop sort+=[largest] return sort #1. find the largest first, then remove it from the lst, #then append the sort
./refactory/data/question_5/code/correct/correct_5_159.py
refactory_data_question_5_correct_5_322
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
./refactory/data/question_5/code/correct/correct_5_322.py
refactory_data_question_5_correct_5_319
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]
./refactory/data/question_5/code/correct/correct_5_319.py
refactory_data_question_5_correct_5_228
def top_k(lst,k): def selection_sort(lst): srt = [] while lst: smallest = lst[0] for elem in lst: if elem < smallest: smallest = elem lst.remove(smallest) srt.append(smallest) return srt return selection_sort(lst)[-1:-k-1:-1]
./refactory/data/question_5/code/correct/correct_5_228.py
refactory_data_question_5_correct_5_040
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]
./refactory/data/question_5/code/correct/correct_5_040.py
refactory_data_question_5_correct_5_373
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]
./refactory/data/question_5/code/correct/correct_5_373.py
refactory_data_question_5_correct_5_216
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]
./refactory/data/question_5/code/correct/correct_5_216.py
refactory_data_question_5_correct_5_179
import heapq def top_k(lst, k): k_sorted = heapq.nlargest(k, lst) return k_sorted
./refactory/data/question_5/code/correct/correct_5_179.py
refactory_data_question_5_correct_5_292
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]
./refactory/data/question_5/code/correct/correct_5_292.py
refactory_data_question_5_correct_5_132
def top_k(lst, k): klist = [] while len(klist) < k: biggest = lst[0] for i in lst: if i > biggest: biggest = i klist.append(biggest) lst.remove(biggest) return klist
./refactory/data/question_5/code/correct/correct_5_132.py
refactory_data_question_5_correct_5_407
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
./refactory/data/question_5/code/correct/correct_5_407.py
refactory_data_question_5_correct_5_099
def top_k(lst, k): result = [] while len(result) < k: biggest = lst[0] for i in lst: if i > biggest: biggest = i lst.remove(biggest) result.append(biggest) return result
./refactory/data/question_5/code/correct/correct_5_099.py
refactory_data_question_5_correct_5_350
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]
./refactory/data/question_5/code/correct/correct_5_350.py
refactory_data_question_5_correct_5_211
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]
./refactory/data/question_5/code/correct/correct_5_211.py
refactory_data_question_5_correct_5_183
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]
./refactory/data/question_5/code/correct/correct_5_183.py
refactory_data_question_5_correct_5_114
def top_k(lst, k): ret = [] for i in range(k): max_int_pos = lst.index(max(lst)) ret.append(lst.pop(max_int_pos)) return ret
./refactory/data/question_5/code/correct/correct_5_114.py
refactory_data_question_5_correct_5_039
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
./refactory/data/question_5/code/correct/correct_5_039.py
refactory_data_question_5_correct_5_248
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
./refactory/data/question_5/code/correct/correct_5_248.py
refactory_data_question_5_correct_5_153
def top_k(lst, k): # Fill in your code here out = [lst[0],] for ele in lst[1:]: for indx in range(len(out)): if out[indx] <= ele: out.insert(indx, ele) break elif indx == len(out) - 1: out.append(ele) return out[0:k]
./refactory/data/question_5/code/correct/correct_5_153.py
refactory_data_question_5_correct_5_416
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
./refactory/data/question_5/code/correct/correct_5_416.py
refactory_data_question_5_correct_5_289
def top_k(lst, k): count = 0 op = [] while count < k: op += [max(lst)] lst.remove(max(lst)) count += 1 return op
./refactory/data/question_5/code/correct/correct_5_289.py
refactory_data_question_5_correct_5_263
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
./refactory/data/question_5/code/correct/correct_5_263.py
refactory_data_question_5_correct_5_202
def top_k(lst, k): new = [] counter = k while counter > 0: curr = 0 for i in range(len(lst)): if lst[i] > lst[curr]: curr = i new.append(lst.pop(curr)) counter -= 1 return new
./refactory/data/question_5/code/correct/correct_5_202.py
refactory_data_question_5_correct_5_356
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]
./refactory/data/question_5/code/correct/correct_5_356.py
refactory_data_question_5_correct_5_158
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) print(sort) return sort[:k]
./refactory/data/question_5/code/correct/correct_5_158.py
refactory_data_question_5_correct_5_014
def top_k(lst, k): sort=[] for i in range (k): biggest=max(lst) lst.remove(biggest) sort.append(biggest) return sort
./refactory/data/question_5/code/correct/correct_5_014.py
refactory_data_question_5_correct_5_055
def top_k(lst, k): ls=[] for i in range(k): ls.append(max(lst)) lst.remove(max(lst)) return ls
./refactory/data/question_5/code/correct/correct_5_055.py
refactory_data_question_5_correct_5_288
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]
./refactory/data/question_5/code/correct/correct_5_288.py
refactory_data_question_5_correct_5_142
def top_k(lst, k): if k == 1: return [max(lst)] else: answer = [] for i in range(min(k, len(lst))): largest = max(lst) answer.append(largest) lst.remove(largest) return answer
./refactory/data/question_5/code/correct/correct_5_142.py