Task 1 - Manipulate Property Data
Task 1 - Manipulate Property Data
In the first task, we will be learning how to generate a data structure by reading a string.
The string that you will read will contain a lot of information and we need to find a way to
store it in a neat and readable data structure such that it can be used for analysis later.
For our purposes, there are two types of properties: a house or an apartment
You will be using a string that we will call property_string. This string will contain
comma-separated values (CSV) of the following fields, in this particular order:
Please note that not all fields will have values for both types of properties. This has been mentioned in
the attribute description if this is the case. If a value is missing, there will be nothing between the
commas at that spot. Please see the examples below to make more sense of this.
for the property with the following keys (with data types of the values in the <>):
● prop_id <str>
● prop_type <str> (this should be set to either 'house' for a house or 'apartment'
for an apartment)
● full_address <str>
● suburb <str> (which you should extract from the address)
● bedrooms <int>
● bathrooms <int>
● parking_spaces <int>
● latitude <float>
● longitude <float>
● floor_number <int> (include this key only if applicable)
● land_area <int> (include this key only if applicable)
● floor_area <int>
● price <int>
● property_features <list of strings>
Some code has been given in the main function for you to test the running of your code
through a couple of examples. Please do not change the code in main, this should run
properly if you have programmed your function correctly.
Next, you will add two functions add_feature(property_dict: dict, feature: str)
and remove_feature(property_dict: dict, feature: str) that will add or remove a
feature from the property features list. These functions shouldn't return anything.
Please note that if the feature you are trying to add already exists, then ignore the new value, don't add
anything in. If you are trying to delete a feature that doesn't exist, then also ignore the request and don't do
anything.
Examples
If the property string is:
As you can see in this dictionary, as this is a house, the key floor_number is not present.
Similarly, when you have a dictionary for an apartment, the key land_area should not be
present.
Another Example:
property_dict = {
"prop_id" : "P10002",
"prop_type": "house",
"full_address" : "9 Delirium Road Toorak VIC 3142",
"suburb": "Toorak",
"bedrooms": 4,
"bathrooms": 2,
"parking_spaces": 2,
"latitude": -37.83993823,
"longitude": 145.0067231,
"land_area": 521,
"floor_area": 357,
"price": 1460000,
"property_features": []
As you can see in this dictionary, since the string had no property features, it has an
empty list.