-
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
Shultz_Cole_Exercise_1_Submission #18
base: main
Are you sure you want to change the base?
Conversation
The edits I made to the live demo2
This is my submission for our exercise this week
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.
#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:
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.
#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.
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.
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.
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.
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.
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.
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.
No description provided.