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

Shultz_Cole_Exercise_1_Submission #18

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

Conversation

ColeShultz
Copy link
Contributor

No description provided.

The edits I made to the live demo2
This is my submission for our exercise this week
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3: count frequency of variable list by checking if request or city is in empty list; 
#if yes, count value is added to list (+1); if not, request/city stored as new key with value of 1

#Code:
#define and check variables
request_type = 'Request Type'
city_name = 'City'
type_list = [d.get(request_type) for d in service_requests if request_type in d]

Fix:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#Code:
#define and check variables
request_type = 'Request Type'
city_name = 'City'
type_list = [d.get(request_type) for d in service_requests if request_type in d]
#print(type_list)
city_list = [d.get(city_name) for d in service_requests if city_name in d]

Fix: Filter out None values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            frequency_dict[item] += 1
        else:
            frequency_dict[item] = 1
    return frequency_dict
    
result1 = count_frequency(type_list)
print(f'The type request count list is as follows: {result1}')

Issue: The function count_frequency is defined twice, once for request types and once for cities. The second definition overwrites the first, which is a logic error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        else:
            frequency_dict[item] = 1
    return frequency_dict
    
result1 = count_frequency(type_list)
print(f'The type request count list is as follows: {result1}')

def count_frequency(city_list):

This overwrites the previous count_frequency function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if item in frequency_dict_2:
            frequency_dict_2[item] += 1
        else:
            frequency_dict_2[item] = 1
    return frequency_dict_2

result2 = count_frequency(city_list)
print(f'The number of requests for each city are as follows: {result2}')

Fix: Use a single generalized function that takes any list and returns a frequency dictionary.

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