Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

stg12793
Copy link
Contributor

No description provided.

@ncsg ncsg deleted a comment from review-notebook-app bot Feb 11, 2025
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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!

Copy link
Contributor

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

Copy link
Contributor

@hzhou715 hzhou715 left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants