Python fundamentals practice problem: dictionaries - laptop purchase (alternative solution acceptable?)

Hi! I completed the laptop purchases practice problem for the dictionaries mission using a different code from the suggested answer. The output I got is the same, but I am just wondering if it is logically sound and therefore an appropriate alternative to the suggested code.

from csv import reader
file = open("laptops.csv")
file_reader = reader(file)
rows = list(file_reader)[1:]

price_to_name = {}
for row in rows:
    price = int(row[2])
    name = row[1]
    if price in price_to_name:
        price_to_name[price].append(name)
    else:
        price_to_name[price] = [name]
      
for price in price_to_name:
    print(price, ":", price_to_name[price])

laptop1 = None
laptop2 = None

for price1 in price_to_name:
    for price2 in price_to_name:
        if price1 == 5000 - price2:
            print(price1, price2)
            
laptop1 = price_to_name[2500][0]
laptop2 = price_to_name[2500][1]
1 Like

Please consider to Include the link to the mission or practice problem. So anyone can navigate easily there and give answer with the context of problem,

GUIDELINE #5: Include a link to mission URL if available

If you ask a question that is specific to one of Dataquest’s course screens, please mention the URL of that screen in your question. There are 2 ways this is helpful:

  1. It gives some much needed context to the community members who may volunteer to help you. You want to make it easy for people to help you, right? As easy as you can.
  2. It invokes our auto-tagging system that tags your question with appropriate tags (based on the course and mission) to make it easier for future learners to find it.

More for full guideline