1
1
import csv
2
2
import os
3
+
3
4
try :
4
5
import statistics
5
6
except :
@@ -31,7 +32,7 @@ def get_data_file():
31
32
32
33
def load_file (filename ):
33
34
with open (filename , 'r' , encoding = 'utf-8' ) as fin :
34
- # with open(filename, 'r') as fin:
35
+ # with open(filename, 'r') as fin:
35
36
reader = csv .DictReader (fin )
36
37
purchases = []
37
38
for row in reader :
@@ -59,8 +60,8 @@ def load_file(filename):
59
60
# def get_price(p):
60
61
# return p.price
61
62
62
- def query_data (data ): # list[Purchase]):
63
-
63
+ def query_data (data ): # list[Purchase]):
64
+
64
65
# data.sort(key=get_price)
65
66
data .sort (key = lambda p : p .price )
66
67
@@ -95,7 +96,7 @@ def query_data(data): # list[Purchase]):
95
96
two_bed_homes = (
96
97
p # projection or items
97
98
for p in data # the set to process
98
- if announce (p , '2-bedrooms, found {}' .format (p .beds )) and p .beds == 2 # test / condition
99
+ if announce (p , '2-bedrooms, found {}' .format (p .beds )) and p .beds == 2 # test / condition
99
100
)
100
101
101
102
homes = []
@@ -108,7 +109,7 @@ def query_data(data): # list[Purchase]):
108
109
ave_baths = statistics .mean ((p .baths for p in homes ))
109
110
ave_sqft = statistics .mean ((p .sq__ft for p in homes ))
110
111
print ("Average 2-bedroom home is ${:,}, baths={}, sq ft={:,}"
111
- .format (int (ave_price ),round (ave_baths , 1 ), round (ave_sqft , 1 )))
112
+ .format (int (ave_price ), round (ave_baths , 1 ), round (ave_sqft , 1 )))
112
113
113
114
114
115
def announce (item , msg ):
@@ -118,9 +119,3 @@ def announce(item, msg):
118
119
119
120
if __name__ == '__main__' :
120
121
main ()
121
-
122
-
123
-
124
-
125
-
126
-
0 commit comments