Screen Link:
https://app.dataquest.io/m/1011/dictionaries-practice-problems/12/laptop-purchase
My Code:
from csv import reader
openfile=open('laptops.csv')
readfile= reader(openfile)
file=list(readfile)[1:]
price_to_name={}
for f in file:
name=f[1]
price= int(f[2])
if price in price_to_name:
price_to_name[price].append(name)
else:
price_to_name[price]=[name]
price_to_name
laptop1=None
laptop2=None
for price in price_to_name:
price1= 5000-price
if price1 in price_to_name and price !=price1:
laptop1=price_to_name[price]
laptop2=price_to_name[price1]
print(price, price1)
print(laptop1,laptop2)
What I expected to happen:
I expected unique laptop names
What actually happened:
Laptop 1 and laptop 2 still gives me none