Untitled
unknown
plain_text
4 years ago
1.4 kB
9
Indexable
def find_max(data):
lst = []
data_int = []
for i in data.items(): # Use values()
for j in i[1]:
lst.append(j)
for s in lst:
if type(s) == type('a'): # type(s) == str
s = int (s)
data_int.append(s)
data_max = max(data_int)
data_type = type(max(data_int)) # data_type = type(data_max)
print((data_max, data_type))
# Use meaningful words to name parameters instead i,j,s
# For line 12, use data_max not max(data_int),
# we don't need to run max function again, just take the result
def check_type(price):
if isinstance(price, int): return price
return int(price)
def find_max_R(data):
price_list = []
for prices in data.values():
for price in prices:
price_list.append(check_type(price))
max_price = max(price_list)
print((max_price, type(max_price)))
realtors = {
"Stephanie": [320000, '460000', 220000, 279000],
"Charles": [209000, 234500],
"Donna": [762000, '455000', 135000],
"Jenny": ['349000', 405000, 129000],
"Mark": [156000, 239000, 260000, '890000']
}
def check_type_short(price):
if isinstance(price, int): return price; return int(price)
def find_max_short(data):
maxPrice = max(map(lambda prices: max(map(lambda price: check_type_short(price), prices)), data.values()))
print((maxPrice, type(maxPrice)))
find_max(realtors)
find_max_R(realtors)
find_max_short(realtors)Editor is loading...