#!/usr/bin/env python # coding: utf-8 # # Sorting: Lab work # ## Exercise 1 # Write the function ```sort4(L)``` that takes a list of 4 elements and sorts it. # The last line of the function must be ```return [L[0]]+sort3(L[1:4])``` # In[ ]: def sort4(L): # # your code goes below # return [L[0]]+ sort3(L[1:4]) # Here are some output examples: # In[ ]: sort4([7,8,1,2]) # In[ ]: sort4([1,9,2,3]) # In[ ]: sort4(['Mickey','Donald','Goofy','Minney']) # ## Exercise 2 # Suppose that you are given the function ```sort9``` that sorts a list of 9 elements. Write a function ```sort10(L)``` that sorts a list L of 10 elements. The last line of the function must be ```return [L[0]]+sort9(L[1,4])``` # In[ ]: # you can use this function as a "black box" but there's no need to read it or understand its code def sort9(L): return sorted(L[0:9]) # In[ ]: def sort10(L): # # your code goes below # return [L[0]] + sort9(L[1:10]) # In[ ]: sort10([0, 1, 6, 10, 9, 3, 3, 9, 9, 5]) # In[ ]: sort10([15, 16, 19, 13, 5, 1, 7, 19, 12, 4]) # In[ ]: sort10([5, 9, 13, 8, 15, 17, 20, 9, 10, 8]) # The array below contains the names of all the students that were registered to the course. # Compute an array that contains these students in alphabetical order by first name. Use the function you wrote to sort it by first name. # In[ ]: L = ['abinet mulugeta', 'urgie huseien', 'yonatan wosenyeleh', 'amanuel asfaw', 'tibebu solomon', 'hailegbrel wudneh', 'gatluk chuol', 'elsabet buzuneh', 'eden ketema', 'maeden seid', 'mikyas legese', 'meskerem birhanu demeke', 'kumneger worku', 'shambel abate', 'hailmeskel shimeles', 'tsega hailu', 'dawit fikeru', 'asmare habitamo', 'zelalem ades', 'betelehem eshetu', 'yosef tadiwos', 'haymanot gidena', 'henock mersha', 'binyam kidane', 'mohammed nur', 'bethelehem walelegn', 'lewi mekonnen', 'wondimu yohanes', 'hodo mukitar', 'yonas adugna', 'tigabu gebrecherkos', 'nardos gesese', 'mohammed nur', 'abdurezak temam', 'shambel elena', 'adem mohamed', 'zakira tebarek', 'lidya gegnaw', 'knesa desta', 'ibrahim ahmed', 'betlehem desalegn', 'adonay geremew', 'kalkidan muluneh', 'haile gebreselasie', 'eden tekilu tilahun', 'ayantu aleneh', 'yosef nosha', 'mebrihity girmay', 'finet hailu', 'elisa feloh', 'bezawit gebremariam', 'nigusu terefe', 'amina bedrie', 'kiflom leuel', 'hana tariku', 'nejat beshir', 'mesfen tamiru', 'shafi abdi', 'kelbesa ambesa', 'abrham tuna', 'daniel hagos', 'yordanos jemberu', 'aman musa', 'habene abdi', 'kawuser jemal', 'tariku erina', 'mesigina gebretsadik', 'yetnayet birhanu', 'semer abrar', 'nur ahmed', 'eman hasen', 'natol gizaw', 'banchayehu asrat', 'hilina thewodros', 'hasen ali', 'mebrihatu lebelo', 'yosef enawgaw', 'nesera teyib', 'mekdes muluneh', 'surafel sewutu', 'mentesenot tefera'] # ## Exercise 3 # # Sort the list above in _reverse alphabetical order_ by first name (so that L[0] will be the name that is last in alphabetical order and L[80] will be the name that is first) # In[ ]: # your code goes here # ## Exercise 4 # Sort the list in alphabetical order by __last name__. # In[ ]: #your code goes here # ### Exercise 5 # # Write a function ```last_name``` that on input a string $s$, will find the first space character ' ' in $s$, and will return the rest of $s$. You don't have to worry about strings that don't contain spaces or contain more than one space. # In[34]: last_name('boaz barak')