From c1815c8fd717fe80ea6654d133fc06207bad30fc Mon Sep 17 00:00:00 2001 From: Lewis Date: Tue, 9 Jan 2018 12:45:54 -0500 Subject: [PATCH] almost done --- __pycache__/exercise.cpython-36.pyc | Bin 0 -> 2205 bytes exercise.py | 54 +++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 __pycache__/exercise.cpython-36.pyc diff --git a/__pycache__/exercise.cpython-36.pyc b/__pycache__/exercise.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7ca6b3c31bbea0accf70466be49df52709731e32 GIT binary patch literal 2205 zcma)7OK;mo5MGjc$Bv!&(WVHBMSPIe%7)~+ZXy^$ocNTYE)cmr$TEnPb}cjJL)j%A zOI1$xH9w?(iPxTV>b1zB=*-fREj2JqaEJSx`F6gU;Sclkg}?tjYz}jT{6%g(FeWdd zskb0FX%cR5lUrS@Y48+JUy-KCGd#<4Fk|sNFYpJ@OYu2A4{K@ukT38>{s`tD^Ceiz zH8XsfufSTCuQo{OtHJk$w~=2fPOam-@_uNfpRY(RQD@4AyXt zIzAPEP)N#@53_alcqfG)fUh(ywV`f@`H(*M8ztmG~O9*6Ve>%Wn5=gl{AK^`qj%$;C1)PTY)x z+m0?Cml4PW=h5`)?9m&g$5fw*jlB*ySU>nhz8cWf9Ec%#M=l}Qp1@SeJQ(4Ik`bp> z&vioR7#DvMiR^yfeqC$*ri4^2vBN5Tcf0i=kY}x}O7;0h1>P4MULbwopmi&f;@qyw zyf$a`r)Uux8LT0dQ?A(Db%PFbRUJCXZm?{fiT=HDOT1LckXG_Z!AGM`L9Y_eE8BOt{|6Sk#>P0JLF=s5Aavplk z^cxJ^X1Wn6<~K9Hux{58BZM}}qd@mhB@r&^Bzg#)kc7q%Qt8sXG=Lg|)xVe|<0z)g z=ag{{+0%t=2?OecC_7THP(Vug;zJUmIwtO)4LTLU3aXusd(_CCPUr+alYKgk1b1WT ze>oWvRQAnj`$PtwjkXlzg?1dKfp#5s66ZlC9Br5Bi!!Zl9p5CxAJ+$Juy%c<27AVb zYSpce8VeAcLX)vIaC$IE>&gc&Dl%x;OIL5UZMM6?wq&si5k8#3V3|6x|fI z>z$Dg;Y+KPJ4#@(bDCLDj{2@u-@#+D!-f>{?Q`ZvLfH_9Hk`M$X}elkKl-sucgpmq zGJT#VnXEA%cVGiIy$4#bcgKl^CFuZ66F*WmYJV*iZjudzgaCkA*-%`0$iZdPK$pJDlPezz-panY0YU(pVpNRh$LJ+5`DWQ|pT6$@@2 zrzP{d0_sWjny?wG@!CD~zZ~Ns3vvzm2c=w`wQcxc+qT50(ltgdVQ(1)#-V(M0=M5X hiLog$HlY@K0gqf!#~@T#WKyYum3vY!K&~uX{{c_HF2eu- literal 0 HcmV?d00001 diff --git a/exercise.py b/exercise.py index 0ae90ce..4eaf18d 100644 --- a/exercise.py +++ b/exercise.py @@ -1,12 +1,34 @@ +""" +Run: + python -m doctest -v exercise.py +""" + # problem 1 # ------------------------------------------------------------------- # people = ['Bob Smith', 'Ken Jones', 'Alex Bradino'] def sort_by_last_name(people, order): + + """ + Takes a list fo full names sorts by last name in either assending or descending order + + arguments: list of names + Assending('A') or Descending ('D') + + return: sorted list + Doctests: + >>> sort_by_last_name(['Bob Smith', 'Ken Jones', 'Alex Bradino'],'A') + ['Alex Bradino', 'Ken Jones', 'Bob Smith'] + """ # return full names sorted by last name in either ascending or descending order # add doctests make sure it passes - pass + + if order == 'A': + return(sorted(people, key=lambda x: x.split()[1])) + else: + return(sorted(people, key=lambda x: x.split()[1], reverse=True)) + # pass # problem 2 @@ -16,17 +38,41 @@ def sort_by_last_name(people, order): def create_dictionary_from_lists(names, ages): + """ + Takes a list of names and adds ages to it to create a new list + + arguments: list of names + list of ages + + return: new dictionary of names and ages + Doctests: + >>> create_dictionary_from_lists(['James', 'Susan', 'Maggie'],[4, 9, 12]) + {'James':4, 'Susan':9, 'Maggie':12} + """ # {'James':4, 'Susan':9, 'Maggie':12} # add doctests make sure it passes - pass + + return dict(zip(names, ages)) + # problem 3 # ------------------------------------------------------------------- # numbers = [5, 6, 7, 8, 9, 10, 11, 12] - + def square_even_values_and_sum_under_10(numbers): + """ + Takes a list of numbers and sums the squares of a list of numbers under 10 + + arguments: list of numbers + + return: sum of squares + Doctests: + >>> square_even_values_and_sum_under_10([5, 6, 7, 8, 9, 10, 11, 12]) + 100 + """ # 6^2 + 8^2] # add doctests make sure it passes - pass + # + return sum((n**2) for n in range(numbers) if n%10 == 2 and n <10) \ No newline at end of file