LAB1FINALBEST

py

School

Pennsylvania State University *

*We aren’t endorsed by this school

Course

132

Subject

Electrical Engineering

Date

Feb 20, 2024

Type

py

Pages

2

Uploaded by MateWasp883

Report
# LAB1 # REMINDER: The work in this assignment must be your own original work and must be completed alone def frequency(txt): ''' >>> frequency('mama') {'m': 2, 'a': 2} >>> answer = frequency('We ARE Penn State!!!') >>> answer {'w': 1, 'e': 4, 'a': 2, 'r': 1, 'p': 1, 'n': 2, 's': 1, 't': 2} >>> frequency('One who IS being Trained') {'o': 2, 'n': 3, 'e': 3, 'w': 1, 'h': 1, 'i': 3, 's': 1, 'b': 1, 'g': 1, 't': 1, 'r': 1, 'a': 1, 'd': 1} ''' # - YOUR CODE STARTS HERE - txt=txt.lower() dict1={} for i in txt: if i.isalpha(): if i not in dict1: dict1[i]=0 dict1[i]+=1 return dict1 def invert(d): """ >>> invert({'one':1, 'two':2, 'three':3, 'four':4}) {1: 'one', 2: 'two', 3: 'three', 4: 'four'} >>> invert({'one':1, 'two':2, 'uno':1, 'dos':2, 'three':3}) {1: ['one', 'uno'], 2: ['two', 'dos'], 3: 'three'} >>> invert({'123-456-78':'Sara', '987-12-585':'Alex', '258715':'sara', '00000':'Alex'}) {'Sara': '123-456-78', 'Alex': ['987-12-585', '00000'], 'sara': '258715'} """ # - YOUR CODE STARTS HERE - dict1 = {} for key in d: if d[key] in dict1: for value in dict1: if value == d[key] and dict1[value]!= key: dict1[d[key]] = [dict1[value], key] else: dict1[d[key]] = key return dict1 def employee_update(d, bonus, year): ''' >>> records = {2020:{"John":["Managing Director","Full- time",65000],"Sally":["HR Director","Full-time",60000],"Max":["Sales Associate","Part-time",20000]}, 2021:{"John":["Managing Director","Full- time",70000],"Sally":["HR Director","Full-time",65000],"Max":["Sales Associate","Part-time",25000]}} >>> employee_update(records,7500,2022)
{2020: {'John': ['Managing Director', 'Full-time', 65000], 'Sally': ['HR Director', 'Full-time', 60000], 'Max': ['Sales Associate', 'Part-time', 20000]}, 2021: {'John': ['Managing Director', 'Full-time', 70000], 'Sally': ['HR Director', 'Full-time', 65000], 'Max': ['Sales Associate', 'Part-time', 25000]}, 2022: {'John': ['Managing Director', 'Full-time', 77500], 'Sally': ['HR Director', 'Full- time', 72500], 'Max': ['Sales Associate', 'Part-time', 32500]}} ''' # - YOUR CODE STARTS HERE - dict1={} for i in d.keys(): dict1=d[i] dict2={} for i in dict1.keys(): dict2[i]=list(dict1[i]) dict2[i][2]+=(bonus) d[year]=dict2 return d if __name__ == "__main__": import doctest #doctest.run_docstring_examples(frequency, globals(), name='LAB1',verbose=True) ## Uncomment this line if you want to run doctest by function. Replace get_words with the name of the function you want to run doctest.testmod() ## Uncomment this line if you want to run the docstring in all functions
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help