From 9a13cb947580354e6f456e53b781aaad374ff353 Mon Sep 17 00:00:00 2001 From: Matejcek Date: Tue, 9 Jan 2018 12:19:26 -0500 Subject: [PATCH 1/2] Matejceks --- __pycache__/exercise.cpython-36.pyc | Bin 0 -> 1670 bytes exercise.py | 27 +++++++++++++++++++++++---- 2 files changed, 23 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..4dbc7d33932de0875377cf3539d44579da001f91 GIT binary patch literal 1670 zcma)+-EY%K5WsisI7vg>gSJ=b>4a9tNvS1MIeZ)tRS_S3K)~@pIGvOxvfS(vOzm~L zYeSn$br0p02ZVUwPq=@{ulJNc;retl&IfIgDpv7iJi9wPGrw8iTv(|5{ol*h<02vd zk`tp0`h9rxa}b5Z@ z0iH+j8Ez)rhjUgEtYvhf=!NNh~=4EoqR#+or%O=@d{F5Xm%t8(y z42Y&U_)=jow&HFgbfW9|8(JET2Gg-hyqyCt^mXD%KN9QP)miXWhgE0cD zRH?9M{qw|%~Uy~hm29uLbbzC*wSBLe7 zc|2VtgJasEP0;l!hyW7kEVhk93cYCz=_g~a&>UAkM*wt;4L74Qqke7}iv`$vT-n4_ zx^dKR{DS_lMny7k&&zXTGmN`_s2dw!H$$hGgP?C4nT2huvx46f`pjwB&*!=QX?i{> zt2NL^778RjDxtt{#HfPe0*F~Tuq;@T{K77Ql1#V`2@;(!9bdW!s+UGWCUy13hBM|!&GR`m)z57bRn+qWI|o5Sun z?Cu!33)pLC(AQk|G}mc+=3LhyksfkohZMdYWEGOyHBJAY=G1S(^pyIY??~({f&zO(T|qS0P4%NHvYOV literal 0 HcmV?d00001 diff --git a/exercise.py b/exercise.py index 0ae90ce..07d9f8c 100644 --- a/exercise.py +++ b/exercise.py @@ -4,9 +4,17 @@ def sort_by_last_name(people, order): + """ + Doctests: + >>> sort_by_last_name(['Bob Smith', 'Ken Jones', 'Alex Bradino'], True) + ['Smith, Bob', 'Jones, Ken', 'Bradino, Alex'] + """ + + for i in range(len(people)): + people[i] = people[i].split(" ")[1] +", " + people[i].split(" ")[0] # return full names sorted by last name in either ascending or descending order # add doctests make sure it passes - pass + return sorted(people, reverse = order) # problem 2 @@ -16,10 +24,14 @@ def sort_by_last_name(people, order): def create_dictionary_from_lists(names, 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 {n:a for n, a in zip(names, ages)} # problem 3 # ------------------------------------------------------------------- # @@ -27,6 +39,13 @@ def create_dictionary_from_lists(names, ages): def square_even_values_and_sum_under_10(numbers): + """ + Argument: List of numbers + Return int + 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 numbers if n % 2 == 0 and n < 10]) From 6ddc77a778374d15219ce6c141998c3dce8820ac Mon Sep 17 00:00:00 2001 From: Matejcek Date: Tue, 9 Jan 2018 12:28:44 -0500 Subject: [PATCH 2/2] Revised --- __pycache__/exercise.cpython-36.pyc | Bin 1670 -> 1751 bytes exercise.py | 5 +---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/__pycache__/exercise.cpython-36.pyc b/__pycache__/exercise.cpython-36.pyc index 4dbc7d33932de0875377cf3539d44579da001f91..278f6a71d018ea5d96d7d91958aa69feff7bcfd3 100644 GIT binary patch delta 618 zcmZ9KO-mb56o${e^O4EaDQ&R^L1_G_Fjhp+jS{lao!}<6i=u>>dy&Y*NzWaH2E~Qq zt_vME?Lu7YIzL93f8bw;E<7jJL>xHho?+hic@LL43+{saLJ;_!hmD`^dH&xw2>>?L z3Y8h5mVgpUp28ul!ihK(%K9TK5Zdj(>5V;>PKcx9x*#1tY<8$BRA!di4%xP*j>xtP zitI{^f|3R3zgweFfOGlFW@J|s?-|vWv&DNlArzToT2UhjWhUq5GqHCIn4=Hf#g*mF z??$89)X9YmkGp;;YM7)RH(TZRBrv>+3+=Ba#-zIayBgI@Qr)XH^;{{6>$S*~X?Sr^ zP7d_};WUjdd$giVx25A&q%$W*rLmX%+&rRZ9|!DD|KaXSG1!q*qquUEhda`e=;@g#j50of&&c%#8Kfa=?BA#ypAU(@W>ahgU@2 zVKTjTCL7aztdHX~uZKAtq7(TN@iRC636SHl$cawn$+Z;#*$e J3+h9|))Tg)eYgMs delta 519 zcmY+By-Ncz7>C~^cl|hf#V^o`NNrsXL@J$xQUo2G3Q|!Jq|{!JlWVUgr)a4N3T_Vd zCY@ZJ{a+NaJLu*j=;Rv@MTb0j^UIqjggn`ocDiia*4f9#_SztQ+hPD<;8?*SYl!3J z5JJ+23vxkLVW)IT`_QL3*rzTgE>oF2TM zu78sJ3&9I|bUy!rGdM&g1wZ0Ka>r1nXm<9vVm|LEQ+9nXR0$b~kh>03i7pSiK38TS zTrL#x?m=XtN3v8=Ym9R4H5c2$ht%%bOD8QU!}hjq>> sort_by_last_name(['Bob Smith', 'Ken Jones', 'Alex Bradino'], True) ['Smith, Bob', 'Jones, Ken', 'Bradino, Alex'] """ - - for i in range(len(people)): - people[i] = people[i].split(" ")[1] +", " + people[i].split(" ")[0] # return full names sorted by last name in either ascending or descending order # add doctests make sure it passes - return sorted(people, reverse = order) + return sorted([n.split(" ")[1] +", " + n.split(" ")[0] for n in people], reverse = order) # problem 2