Question
Using python and python dictonaries Updated Text format: from seyarticles import sey_articles from pprint import pprint from copy import deepcopy ''' Do not handle exceptions
Using python and python dictonaries
Updated Text format:
from seyarticles import sey_articles
from pprint import pprint
from copy import deepcopy
'''
Do not handle exceptions using try/except unless explicitly instructed to do so.
General exceptions are not allowed!
>>>>> PLEASE DO NOT REMOVE THE INSTRUCTIONS FROM WITHIN EACH OF THE QUESTIONS BELOW.
'''
# ************************************************************************************
# This is a 'global' variable that is automatically available to all of the functions.
# DO NOT ALTER IT IN ANY OF YOUR CODE!!
# ************************************************************************************
articles = {'How 2 Code With Python': {'Author': 'Trav', 'Year': 2020},
'I Remember Vera': {'Author': 'Jayne', 'Year': 2020},
'CogSci Coding In Python': {'Author': 'Trav', 'Year': 1988},
'Kick Em In The Engine': {'Author': 'Jayne', 'Year': 2006},
"I'm Pointing Right At It": {'Author': 'Kaylee', 'Year': 2006}}
def dictOdict_year(year: int) -> tuple:
'''
**this function uses the global variable called articles
Given a year, return a tuple of all articles published in the given year.
E.g., dict0dict_year(2020) should return:
('Travis. (2020). How 2 Code With Python.',
'Jayne. (2020). I Remember Vera.')
If there are no valid articles, return an empty tuple
'''
print("***REPLACE*** This line with you own code.")
def dictOdict_author(author: str) -> tuple:
'''
**this function uses the global variable called articles
Given a year, return a tuple of all articles published by the given author.
E.g., dict0dict_author("Travis") should return:
('Travis. (2020). How 2 Code With Python.', 'Travis. (1988). CogSci Coding In Python.')
If there are no valid articles, return an empty tuple
'''
print("***REPLACE*** This line with you own code.")
def dictOdict_title(title: str) -> tuple:
'''
**this function uses the global variable called articles
Given a year, return a tuple of all articles published with the given title.
E.g., dictOdict_title("Kick Em In The Engine") should return:
('Jayne. (2006). Kick Em In The Engine.',)
If there are no valid articles, return an empty tuple
'''
print("***REPLACE*** This line with you own code.")
def dictOdict_year_fancy(year: int, compare: str) -> tuple:
'''
Same as dictOdict_year() except:
- it now has a comparison parameter that expects one of these strings "eq" "gt" or "lt",
which stands for equals greater-than and less-than. If not, return an empty tuple after printing this message "The comparison argument must be eq, gt, or lt".
- obviously, you will return results based on whether the articles fit the comparison. E.g.,
if the input is year=2000 and compare="gt", then you will return all articles whose
the year is greater than 2000, i.e.:
- if year is a string rather than an int, just convert it. If that fails, (e.g., if year is a list),
then return an empty tuple and print "The given year is not valid".
'''
print("***REPLACE*** This line with you own code.")
def remove_a_dict_item_by_key(item: str) -> dict:
'''
Using the clothing dict below, return the entire dict with the specified item removed.
In this case, do not make a new dict, instead remove the item from the existing dict and
then return it. E.g., if item='hat', this func would return:
{'pants': ['blue', 'denim'], 'shirt': ['white', 'flannel']}
if item is not a key in the dict, return an empty dict.
'''
# do not alter the clothing variable at any point in your code!
clothing = {'pants': ['blue', 'denim'], 'shirt': ['white', 'flannel'], 'hat': ['blue', 'wool']}
print("***REPLACE*** This line with you own code.")
def remove_a_dict_item_by_content(content: str) -> dict:
'''
Using the clothing dict below, return the entire dict with the specified item removed.
Unlike the previous function, this one does not care about the keys.
Also unlike in the previous function, you can decide whether to create a new dict and
return it, or alter the existing dict and return it.
It only considers whether the string in the content parameter is a member of one of the
lists in the dict.
E.g., if content='denim', this func would return:
{'shirt': ['white', 'flannel'], 'hat': ['blue', 'wool']}
if content is not in any of the lists, return the entire dict unaltered.
'''
# do not alter the clothing variable at any point in your code!
clothing = {'pants': ['blue', 'denim'], 'shirt': ['white', 'flannel'], 'hat': ['blue', 'wool']}
print("***REPLACE*** This line with you own code.")
def filter_sey_articles(filter: dict) -> tuple:
'''
You'll start with the provided data structure called sey_articles
# NOTE: the sey_articles list contains a series of dicts. Each with keys of 'authors', 'title', 'year', and 'journal'
When queried, this function should return a tuple of dicts representing the appropriate article(s).
The filter parameter expects a dict argument whose keys and values indicate which article(s) to return.
E.g., if filter = {'authors': 'Fraynt'}, you would return:
({'authors': ['Seymour', 'Fraynt'], 'journal': 'Appl Psychophysiol Biofeedback',
'title': 'Time and Encoding Effects in the Concealed Knowledge Test', 'year': 2009},)
# Note Fraynt was only 1 of the authors of that ^^^ article.
if filter = {'year': 2009), you would return:
({'authors': ['Seymour', 'Schumacher'], 'journal': 'Cognitive Affective & Behvioral Neuroscience',
'title': 'Electromyographic Evidence for Response Conflict in the Exclude Recognition Task', 'year': 2009},
{'authors': ['Seymour', 'Fraynt'], 'journal': 'Appl Psychophysiol Biofeedback',
'title': 'Time and Encoding Effects in the Concealed Knowledge Test', 'year': 2009})
if more than one filter is given, you have to filter your output accordingly.
E.g., if filter = {'author': 'Seymour', 'title': 'Executive'}, you would return:
({'authors': ['Meyer', 'Glass', 'Mueller', 'Seymour', 'Kieras'], 'journal': 'European Journal of Cognitive Psychology', 'title': 'Executive-Process Interactive Control: A Unified Computational Theory for Answering Twenty Questions and more About Cognitive Aging', 'year': 2001},)
# ^^^ note that 'Executive' is only part of a title.
If the filter does not match any of the records, return an empty tuple.
If any the keys in filter is not one of the expected keys, ignore it (no error is raised).
if none of the keys in filter are one of the expected keys, then just return an empty tuple.
You do not have to worry about any other kind of mal-formed input. The test for this function will always
call it with a normal dict with one or more key-value pairs. All keys and values will be strings unless
a year is being filtered, in that case the value will be an integer (e.g., {'year': 2018})
'''
# sey_articles is a list of dicts already imported at the top of this file. You can just use it in your code.
# however, you should not alter it! Here is an example element of sey_articles:
# {'authors': ['Goodman', 'Seymour', 'Anderson'], 'journal': 'Computers in Human Behavior',
# 'title': 'Achieving the performance benefits of hands-on experience when using digital devices: A representational approach',
# 'year': 2016}
# Start like this, do not alter this line, but you are free to alter the results variable if it helps
results = deepcopy(sey_articles) # makes independent copy of sey_articles list and it's dict values
print("***REPLACE*** This line with you own code.")
'''
****************** YOU CAN/SHOULD EDIT WHAT IS CALLED BELOW.
****************** AN EXAMPLE CALL TO average() IS GIVEN SO YOU CAN SEE HOW IT'S DONE.
'''
if __name__ == '__main__': # >>
# Add your function calls here to try out your code.
print(dictOdict_year(1970))
Python from seyarticles import sey articles from pprint import pprint from copy import deepcopy Do not handle exceptions using try/except unless explicitly instructed to do so. General exceptions are not allowed! >>>>> PLEASE DO NOT REMOVE THE INSTRUCTIONS FROM WITHIN EACH OF THE QUESTIONS BELOW. >>>>> I NEED THESE PROMPTS TO BE IN PLACE DURING GRADING! # This is a global' variable that is automatically available to all of the functions. # DO NOT ALTER IT IN ANY OF YOUR CODE!! articles = {"How 2 Code With Python': {'Author': 'Trav', 'Year: 2020). 'I Remember Vera': {'Author': 'Jayne', 'Year: 2020). 'CogSci Coding in Python': {'Author': 'Trav', 'Year: 1988). "Kick Em In The Engine': {'Author': 'Jayne, "Year: 2006), "I'm Pointing Right At It": {'Author': "Kaylee', 'Year: 2006}} def dictOdict year(year: int) -> tuple: **this function uses the global variable called articles Given a year, return a tuple of all articles published in the given year. E.g., dictOdict_year(2020) should return: ('Travis. (2020). How 2 Code With Python., Jayne. (2020). I Remember Vera.) If there are no valid articles, return an empty tuple B12 print("***REPLACE*** This line with you own code.") def dictOdict author(author: str) -> tuple: **this function uses the global variable called articles Given a year, return a tuple of all articles published by the given author. E.g., dictOdict_author("Travis") should return: ('Travis. (2020). How 2 Code With Python., 'Travis. (1988). CogSci Coding in Python.) If there are no valid articles, return an empty tuple print("***REPLACE*** This line with you own code.") BIL def dictodichtitle(title: str) -> tuple: **this function uses the global variable called articles Given a year, return a tuple of all articles published with the given title. E.g., dictOdict title("Kick Em In The Engine") should return: ('Jayne. (2006). Kick Em In The Engine.:) If there are no valid articles, return an empty tuple BER !!! print("***REPLACE*** This line with you own code.") def dictOdict year fancy[year: int, compare: str) -> tuple: Same as dictOdict year() except: - it now has a comparison parameter that expects one of these strings eq" "at" or "It". which stands for equals greater than and less-than. If not, return an empty tuple after printing this message "The comparison argument must be eq, at or it": - obviously you will return results based on whether the articles fit the comparison. E.g., if the input is year=2000 and compare="gt", then you will return all articles whose year is greater than 2000, i.e.: - if year is a string rather than an int, just convert it. If that foils, (e.g., if year is a list). then return an empty tuple and print "The given year is not valid. print(****REPLACE*** This line with you own code.") def remove a dict. item by.key(item: str) -> dict: Using the clothing dict below, return the entire dict with the specified item removed. In this case, do not make a new dict, instead remove the item from the existing dict and then return it. E.g., if item='hat", this func would return: ('pants': ['blue', 'denim"), "shirt': ['white', 'flannel"]} if item is not a key in the dict, return an empty dict. # do not alter the clothing variable at any point in your code! clothing = {'pants': ['blue', 'denim'), "shirt': ['white', "iannel"], "hat': ['blue', 'wood"}} print(****REPLACE*** This line with you own code.") def remove_a_dict item by content content: str) -> dict: Using the clothing dict below, return the entire dict with the specified item removed. Unlike the previous function, this one does not care about the keys. Also unlike in the previous function, you can decide whether to create a new diet and return it, or alter the existing dict and return it. It only considers whether the string in the content parameter is a member of one of the lists in the dict. E.g., if content="denim', this func would return: ' shirt': ['white', 'flannel'). "hat': ['blue', 'wool']} if content is not in any of the lists, return the entire dict unaltered. # do not alter the clothing variable at any point in your code! clothing = ('pants': ['blue', 'denim'], "shirt': ['white', 'flannel], "hat': ['blue', 'wool']} print("***REPLACE*** This line with you own code.") H def filter_sey_articles (filter: dict) -> tuple: You'll start with the provided data structure called sey_articles # NOTE: the sey_articles list contains a series of dicts. Each with keys of authors', 'title', 'year', and 'journal When queried, this function should return a tuple of dicts representing the appropriate article(s). The filter parameter expects a dict argument whose keys and values indicate which article(s) to return. E.g., if filter = {'authors': "Fraynt"), you would return: (l'authors': ["Seymour, "Fraynt"), "journal': 'Appl Psychophysiol Biofeedback, "title': 'Time and Encoding Effects in the Concealed knowledge Test year: 2009). # Note Fraynt was only 1 of the authors of that man article. if filter = ('year: 2009), you would return: {{"authors': ["Seymour', 'Schumacher'), "journal': 'Cognitive Affective & Behvioral Neuroscience "title': 'Electromyographic Evidence for Response Conflict in the Exclude Recognition Task', 'year: 2009). {"authors': [Seymour', 'Fraynt'], "journal': 'Appl Psychophysiol Biofeedback, "title': 'Time and Encoding Effects in the Concealed Knowledge Test', 'year': 2009) If more than one filter is given, you have to filter your output accordingly. E.g., if filter = {'author': 'Seymour', 'title': "Executive'), you would return: ("authors': ['Meyer, "Glass", "Mueller', 'Seymour", "Kieras 1. sournal: "European Journal of Cognitive Psychology'. "title": "Executive Process Interactive Control: A Unified Computational Theory for Answering Twenty Questions and more About Cognitive Aging: 'year': 2001).) # and note that 'Executive' is only part of a title. If the filter does not match any of the records, return an empty tuple. If any the keys in filter is not one of the expected keys, ignore it (no error is raised). if none of the keys in filter are one of the expected keys, then just return an empty tuple. You do not have to worry about any other kind of mal-formed input. The test for this function will always call it with a normal dict with one or more key-value pairs. All keys and values will be strings unless a year is being filtered, in that case the value will be an integer (e.... [year: 2018}} #sey_articles is a list of dicts already imported at the top of this file. You can just use it in your code. # however, you should not alter It! Here is an example element of sey_articles: # l'authors': ['Goodman, 'Seymour', 'Anderson'], "journal': 'Computers in Human Behavior # 'title': 'Achieving the performance benefits of hands-on experience when using digital devices: A representational approach', # 'year': 2016) # Start like this, do not alter this line, but you are free to alter the results variable if it helps results - deepcopy(sey articles) # makes independent copy of sey_articles list and it's dict values print(****REPLACE*** This line with you own code.)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started