From aa41064836bab5bfc0700ee234915421127d67c8 Mon Sep 17 00:00:00 2001 From: Halm Date: Tue, 9 Jan 2018 11:39:07 -0600 Subject: [PATCH 1/2] Add answers --- __pycache__/exercise.cpython-36.pyc | Bin 0 -> 1453 bytes exercise.py | 23 +++++++++++++++++++---- 2 files changed, 19 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..489bce01cc8015b58ed99a67ca1e1560dc6871a4 GIT binary patch literal 1453 zcma)6&2Aev5GHr^XZa^}>=+2p!xlcs0vtn11GI4*p>>KLQq(;-y{HNn)RIxR-XDeB zwXKbf9-M0reT+UvUt_O5?JERm(Ql|mu-&2vAiYWuH0Ukrb)Gxi6& zHd@fXz%)k?l1VO|i92M{m9@8Q$YotNWD`4%Y{@0rhUUs;xq`ErT$O9`j{FGw>+&wn zTEn{BkefJb$a}}EyHzY5rep6o4znMNrEgT?Jx>#5ij^-Tb?zN%A;TmM90aC8Uu4Ig zVVb)T8N0Cgyk!?$y1%&aSSx;Sdl*7b@>nIA*|*E@v{c%A>b=mp^1@f%EX}<$kz`($ zdM4GGCzT0Qf^d^3-q#{B|7|7S8?~+1!C+u-`{S7(36uGWh}F(irPE05+E`s{_d{oa zva{=T7C32f9ckyKH4iwj(V#DZKE^aF5Etwxb_K}yvDI~sDl+KuvTmkPm_gy^zcF3I z=DSDF_DA0vrOikMr{=6b9i656Wc0At|NKD@zsC>aR40HtQs+tsp;3F&S=l;>L_C&a zuuc&%S+Py@+yJ>? z^?$i{sV?4MlM) zx?5o~O^_`|;LX|Vl{~q{*t_-tRVYZ~>0l4WmY)VIKKlR!*IW0!4>YR_lnB@S2Vcp@ zw_=vtAK<)0$q)goxyJQ2zDM1rrs~)}*7T31H%L$^^(Q3A>RK$it?j#L9mJ{3BQ>> sort_by_last_name(people, True) + ['Bob Smith', 'Ken Jones', 'Alex Bradino'] + """ + + return sorted(people, key=lambda x: x.split()[1], reverse=order) # problem 2 # ------------------------------------------------------------------- # @@ -18,8 +25,11 @@ def sort_by_last_name(people, order): def create_dictionary_from_lists(names, ages): # {'James':4, 'Susan':9, 'Maggie':12} # add doctests make sure it passes - pass - + """ + >>> create_dictionary_from_lists(names, ages) + {'James': 4, 'Susan': 9, 'Maggie': 12} + """ + return dict(zip(names,ages)) # problem 3 # ------------------------------------------------------------------- # @@ -29,4 +39,9 @@ def create_dictionary_from_lists(names, ages): def square_even_values_and_sum_under_10(numbers): # 6^2 + 8^2] # add doctests make sure it passes - pass + """ + >>> square_even_values_and_sum_under_10(numbers) + 100 + """ + b=[n**2 for n in numbers if n%2==0 and n<10] + return sum(b) From df924d8ab159ccd5d987aefe9f910e0bc6585239 Mon Sep 17 00:00:00 2001 From: Halm Date: Tue, 9 Jan 2018 11:54:31 -0600 Subject: [PATCH 2/2] Added notes --- exercise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercise.py b/exercise.py index 7d8df90..c0d0c27 100644 --- a/exercise.py +++ b/exercise.py @@ -14,7 +14,7 @@ def sort_by_last_name(people, order): ['Bob Smith', 'Ken Jones', 'Alex Bradino'] """ - return sorted(people, key=lambda x: x.split()[1], reverse=order) + return sorted(people, key=lambda x: x.split()[1], reverse=order) #add key= if you want to do something other than the default (which would have been the first name) # problem 2 # ------------------------------------------------------------------- #