-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completed exercise 01_Sam Gordon #19
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Location': 'REAL ESTATE SIGNAGE HAS BEEN OBSTRUCTING AND POSTED PASS THE HOURS OF ALLOWED TIME FOR OVER 3 WEEKS AT THE INTERSECTION OF GEORGIA AVE AND FOREST GLEN ROAD IN SILVER SPRING MD 20902',
'City': None,
'ZIP code': None
}
]
# Counts of each type of request
request_type_counts = {}
Great! Use dictionary to save type and count number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
]
# Counts of each type of request
request_type_counts = {}
# Reviews each separate request and takes note of type
for request in service_requests:
request_type = request.get('Request Type')
Effective! Use get function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get() method returns the value of the item with the specified key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Reviews each separate request and takes note of type
for request in service_requests:
request_type = request.get('Request Type')
# If request type exists, add one (1) count; if not, then it starts at zero
if request_type:
request_type_counts[request_type] = request_type_counts.get(request_type, 0) + 1
I googled the meaning of get(a,0). The get() method is used to retrieve the value associated with a specified key in a dictionary. If the key is not found, it returns a default value, 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
city = request.get('City')
# If listed city exists, add one (1) count; if not, then it starts at zero
if city:
city_counts[city] = city_counts.get(city, 0) + 1
# Print Final Results
print("City Counts:", city_counts)
Easily understandable!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Every time a new request is identified, add it to the new dictionary.
- After all requests are reviewed, print results.
- Create new dictionary to store count for each listed city.
- Review all of the requests.
- Every time a new city is identified, add it to the new dictionary.
- After all requests are reviewed, print results.
Clear and effective
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pseudocode is logic and easily understandable. The code mainly uses get() function to retrieve the value associated with a specified key in a dictionary. It is effective and sleek. I learned the get() function from the code. Great work. Thanks!
No description provided.