{"reference_solution":"def search(x, seq):\n for i in range(len(seq)):\n if x <= seq[i]:\n return i\n return len(seq)","assignment_id":1,"func_name":"search","test":"assert search(42, (-5, 1, 3, 5, 7, 10))==6 and search(42, [1, 5, 10])==3 and search(5, (1, 5, 10))==1 and search(7, [1, 5, 10])==2 and search(3, (1, 5, 10))==1 and search(-5, (1, 5, 10))==0 and search(10, (-5, -1, 3, 5, 7, 10))==5 and search(-100, (-5, -1, 3, 5, 7, 10))==0 and search(0, (-5, -1, 3, 5, 7, 10))==2 and search(100, [])==0 and search(-100, ())==0","description":"Task: Sequential Search"} {"reference_solution":"def unique_day(day, possible_birthdays):\n count = 0\n for birthday in possible_birthdays:\n if birthday[1] == day:\n count += 1\n return count == 1\n\ndef unique_month(month, possible_birthdays):\n count = 0\n for birthday in possible_birthdays:\n if birthday[0] == month:\n count += 1\n return count == 1\n\ndef contains_unique_day(month, possible_birthdays):\n for birthday in possible_birthdays:\n if birthday[0] == month and unique_day(birthday[1], possible_birthdays):\n return True\n return False\n","assignment_id":2,"func_name":"unique_day-unique_month-contains_unique_day","test":"\n\ntuple_of_possible_birthdays = (('May', '15'),\n ('May', '16'),\n ('May', '19'),\n ('June', '17'),\n ('June', '18'),\n ('July', '14'),\n ('July', '16'),\n ('August', '14'),\n ('August', '15'),\n ('August', '17'))\n\nassert unique_day(\"1\", ((\"January\",\"1\"),(\"February\",\"1\")))==False and unique_month(\"January\", ((\"January\",\"1\"),(\"January\",\"2\")))==False and unique_month(\"January\", ((\"January\",\"1\"),(\"February\",\"1\")))==True and contains_unique_day(\"January\", ((\"January\",\"1\"),(\"January\",\"2\")))==True and contains_unique_day(\"January\", ((\"January\",\"1\"),(\"February\",\"1\")))==False and contains_unique_day(\"February\", ((\"January\",\"10\"),(\"February\",\"1\"),(\"February\",\"10\")))==True and unique_day(\"3\", ((\"January\",\"1\"),(\"January\",\"2\")))==False and unique_month(\"March\", ((\"January\",\"1\"),(\"February\",\"1\")))==False and unique_day(\"1\", ((\"January\",\"1\"),(\"January\",\"2\")))==True and unique_day(\"16\", tuple_of_possible_birthdays)==False and unique_day(\"17\", tuple_of_possible_birthdays)==False and unique_day(\"18\", tuple_of_possible_birthdays)==True and unique_day(\"19\", tuple_of_possible_birthdays)==True and unique_month(\"May\", tuple_of_possible_birthdays)==False and unique_month(\"June\", tuple_of_possible_birthdays)==False and contains_unique_day(\"June\", tuple_of_possible_birthdays)==True and contains_unique_day(\"July\", tuple_of_possible_birthdays)==False","description":"Task: Unique dates and months\n\n\nImplement unique_day, unique_month and contains_unique_day."} {"reference_solution":"def remove_extras(lst):\n newlist = []\n for i in lst:\n if i not in newlist:\n newlist.append(i)\n return newlist\n","assignment_id":3,"func_name":"remove_extras","test":"from collections import OrderedDict\nassert remove_extras([1, 1, 1, 2, 3])==[1, 2, 3] and remove_extras([1, 5, 1, 1, 3, 2])==[1, 5, 3, 2] and remove_extras([])==[] and remove_extras([3, 4, 5, 1, 3])==[3, 4, 5, 1] and remove_extras([3, 4, 5, 1, 3])==[3, 4, 5, 1] and remove_extras([3, 4, 5, 1, 3])==[3, 4, 5, 1]","description":"Task: Duplicate elimination\n\n\nWrite a function remove_extras(lst) that takes in a list and returns a new list with\nall repeated occurrences of any element removed. For example, remove_extras([5,\n2, 1, 2, 3]) returns the list [5, 2, 1, 3]."} {"reference_solution":"def sort_age(lst):\n for i in range(0, len(lst)-1):\n for j in range(i+1, len(lst)):\n if lst[i][1] < lst[j][1]:\n tmp = lst[i]\n lst[i] = lst[j]\n lst[j] = tmp\n return lst","assignment_id":4,"func_name":"sort_age","test":"assert sort_age([(\"F\", 19)])==[('F', 19)] and sort_age([(\"M\", 35), (\"F\", 18), (\"M\", 23), (\"F\", 19), (\"M\", 30), (\"M\", 17)])==[('M', 35), ('M', 30), ('M', 23), ('F', 19), ('F', 18), ('M', 17)] and sort_age([(\"F\", 18), (\"M\", 23), (\"F\", 19), (\"M\", 30), (\"M\", 17)])==[('M', 30), ('M', 23), ('F', 19), ('F', 18), ('M', 17)] and sort_age([(\"F\", 18), (\"M\", 23), (\"F\", 19), (\"M\", 30)])==[('M', 30), ('M', 23), ('F', 19), ('F', 18)] and sort_age([(\"M\", 23), (\"F\", 19), (\"M\", 30)])==[('M', 30), ('M', 23), ('F', 19)] and sort_age([])==[]","description":"Task: Sorting Tuples\n\n\nCan we sort items other than integers? For this question, you will be sorting tuples!\nWe represent a person using a tuple (, ). Given a list of people, write\na function sort_age that sorts the people and return a list in an order such that the older\npeople are at the front of the list. An example of the list of people is [(\"M\", 23), (\"F\",\n19), (\"M\", 30)]. The sorted list would look like [(\"M\", 30), (\"M\", 23), (\"F\", 19)]. You\nmay assume that no two members in the list of people are of the same age."} {"reference_solution":"def top_k(lst, k):\n ls = []\n for i in range(k):\n ls.append(max(lst))\n lst.remove(max(lst))\n return ls","assignment_id":5,"func_name":"top_k","test":"import heapq\nassert top_k([9, 9, 4, 9, 7, 9, 3, 1, 6], 5)==[9, 9, 9, 9, 7] and top_k([9, 8, 4, 5, 7, 2, 3, 1, 6], 5)==[9, 8, 7, 6, 5] and top_k([4, 5, 2, 3, 1, 6], 6)==[6, 5, 4, 3, 2, 1] and top_k([4, 5, 2, 3, 1, 6], 3)==[6, 5, 4] and top_k([4, 5, 2, 3, 1, 6], 0)==[]","description":"Task: Top-K\n\n\nWrite a function top_k that accepts a list of integers as the input and returns the greatest\nk number of values as a list, with its elements sorted in descending order. You may use\nany sorting algorithm you wish, but you are not allowed to use sort and sorted."}