Skip to content

Commit 91dc80c

Browse files
committed
link to you try output code.
1 parent bf1aee0 commit 91dc80c

File tree

1 file changed

+46
-7
lines changed
  • apps/09_real_estate_analyzer/you_try

1 file changed

+46
-7
lines changed

apps/09_real_estate_analyzer/you_try/README.md

+46-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,30 @@ Key concepts introduced
1818

1919
Dictionaries are data structures which allow random access by a key (string, number, whatever). They are extremely common and powerful in Python.
2020

21-
info = dict() # {} info['age'] = 42 info['loc'] = 'Italy' info = dict(age=42, loc='Italy') info = {'age': 42, 'loc': 'Italy'} location = info['loc'] if 'age' in info: # use info['age']
21+
info = dict() # {}
22+
info['age'] = 42
23+
info['loc'] = 'Italy'
24+
25+
info = dict(age=42, loc='Italy')
26+
info = {'age': 42, 'loc': 'Italy'}
27+
28+
location = info['loc']
29+
30+
if 'age' in info:
31+
# use info['age']
2232

2333
**Lambdas**
2434

2535
Lambdas are small inline methods.
2636

27-
def find_sig_nums(nums, predicate): for n in nums: if predicate(n): yield n numbers = [1, 1, 2, 3, 5, 8, 13, 21, 34] sig = find_sig_nums(numbers, lambda x: x % 2 == 1) # sig -> [1, 1, 3, 5, 13, 21]
37+
def find_sig_nums(nums, predicate):
38+
for n in nums:
39+
if predicate(n):
40+
yield n
41+
42+
numbers = [1, 1, 2, 3, 5, 8, 13, 21, 34]
43+
sig = find_sig_nums(numbers, lambda x: x % 2 == 1)
44+
# sig -> [1, 1, 3, 5, 13, 21]
2845

2946
**CSV File Parsing**
3047

@@ -40,18 +57,40 @@ Lambdas are small inline methods.
4057

4158
**py2 vs py3**
4259

43-
try: import statistics # only Python 3.4.3+ except: # statitics_2_stand_in defines a mean method import statitics_2_stand_in as statistics
60+
try:
61+
import statistics # only Python 3.4.3+
62+
except:
63+
# statitics_2_stand_in defines a mean method
64+
import statitics_2_stand_in as statistics
4465

4566
# Can use statistics.mean as needed
4667

47-
numbers = [1, 6, 99, ..., 5] the_ave = statistics.mean(numbers)
68+
numbers = [1, 6, 99, ..., 5]
69+
the_ave = statistics.mean(numbers)
4870

4971
**List comprehensions**
5072

51-
paying_usernames = [ u.name for u in get_active_customers() if u.last_purchase == today ]
52-
# paying_usernames is a list
73+
paying_usernames = [
74+
u.name
75+
for u in get_active_customers()
76+
if u.last_purchase == today
77+
]
78+
# paying_usernames is a list
5379

5480
**Generator expressions**
5581

56-
paying_usernames = ( u.name for u in get_active_customers() if u.last_purchase == today ) # paying_usernames is a generator
82+
paying_usernames = (
83+
u.name
84+
for u in get_active_customers()
85+
if u.last_purchase == today
86+
)
87+
# paying_usernames is a generator
88+
89+
90+
------------------
91+
92+
Note: To see finished code that outputs the expected
93+
numbers, you can use this alternate branch:
5794

95+
App 9's [program.py](https://github.com/mikeckennedy/python-jumpstart-course-demos/blob/app_9_matching_output/apps/09_real_estate_analyzer/final/program.py)
96+
for this "you try" section

0 commit comments

Comments
 (0)