Screen Link:
My Code:
class Inventory():
def __init__(self, csv_filename):
with open('C:/Users/TimKa/OneDrive/Data Eng Study/Guided Projs/laptops.csv') as file:
rows = list(csv.reader(file))
self.header = rows[0]
self.rows = rows[1:]
for row in self.rows:
row[-1] = int(row[-1])
self.id_to_row = {}
for row in self.rows:
self.id_to_row[row[0]]= row
self.prices = set() #step 1
for row in self.rows: # the row has stored the data for each laptop as a list
self.prices.add(row[-1]) # step 2
self.rows_by_price = sorted(self.rows, key=row_price)
for row in self.rows_by_price:
row[-1] = int(row[-1])
print(self.rows_by_price)
def check_range_fast(self, min_price, max_price):
for price in self.rows_by_price:
if max_price > price[-1] > min_price:
return self.rows_by_price[price[-1]]
return None
What I expected to happen:
A list of rows which show all the laptops priced between a given range of numbers
What actually happened:
['7746281', 'Dell', 'Inspiron 3567', 'Notebook', '15.6', 'Full HD 1920x1080', 'Intel Core i3 6006U 2GHz', '4GB', '1TB HDD', 'AMD Radeon R5 M430', 'Windows 10', '2.2kg', 449]
I get a row that is outside my range. I want to write a query that finds all laptops whose price is in the given range.