You're looking for an apartment that fits your budget and has a certain amount of bedrooms. You have some apartment data that is structured as a list of dictionaries, with each dictionary describing one apartment. For example:

apartments = [{"location":"North End", "rent":2200, "num_beds": 1},
{"location":"Beacon Hill", "rent":2500, "num_beds": 1},
{"location": "Lowell", "rent": 1500, "num_beds": 2},
{"location": "Medford", "rent": 1700, "num_beds": 2}]

Write a function called apartment_search that takes three arguments:
● apartments: the apartment data (use the above sample for development),
● rent (integer): the monthly rent you can pay (inclusive),
● num_bedrooms (integer): the minimum number of bedrooms that you're willing to take.

The function will return a list of unique locations in which matching apartments are found, sorted alphabetically. Your submission file should be called For example, the search in the above sample data for apartments with at least 1 bedroom and below 2000 should return ['Lowell', 'Medford'].

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

def apartment_search(apartments, rent, num_bedrooms):
    # create an empty list
    search = []
    # iterate over the dictionary
    for ap in apartments:
       # check for rent and bedroom requirements
       if rent >= ap['rent'] and num_bedrooms <= ap['num_beds'] :
            # push the location to list if all requirements are met
            location = ap['location']...

By purchasing this solution you'll be able to access the following files:

50% discount

$10.00 $5.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats