Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python: toontown simulates more complicated processing on a 2-dimension table. g

ID: 3592411 • Letter: P

Question

python:

toontown simulates more complicated processing on a 2-dimension table. get a copy of the program, then make the changes to the template so the program is functional. Your new output should look similar

toons is the only global variable and it must be immutable. The functional code should contain;

1.No global variables, preferably no variables all

2.If you have local variables, make sure they are immutable,

3. No looping

Try to use Lambdas and map()/reduce()when possible. Use deepcopy()from the copy module to propagate new copies of toons

https://pastebin.com/ULJPHmnb

Explanation / Answer

The code so far modified

toons = [{'fname':'Mickey', 'lname':'Mouse', 'gender':'m'},
{'fname':'Minnie', 'lname':'Mouse', 'gender':'f'},
{'fname':'Yosemite', 'lname':'Sam', 'gender':'m'}]

def update_toons(toons):
for toon in toons:
toon['greeting'] = ' '.join(['Mr' if toon['gender'] == 'm' else 'Ms',
toon['fname'],
toon['lname']])
toon['gender'] = 'male' if toon['gender'] == 'm' else 'female'
toon['address'] = 'ToonTown'

update_toons(toons)

print(toons)
==> [{'fname':'Mickey', 'lname':'Mouse', 'gender':'male', 'greeting':'Mr Mickey Mouse', 'address':'ToonTown'},
{'fname':'Minnie', 'lname':'Mouse', 'gender':'female', 'greeting':'Ms Minnie Mouse', 'address':'ToonTown'},
{'fname':'Yosemite', 'lname':'Sam', 'gender':'male', 'greeting':'Mr Yosemite Sam', 'address':'ToonTown'}]

toons = [{'fname':'Mickey', 'lname':'Mouse', 'gender':'m'},
{'fname':'Minnie', 'lname':'Mouse', 'gender':'f'},
{'fname':'Yosemite', 'lname':'Sam', 'gender':'m'}]

print (pipeline(toons, [create_greeting,update_gender,create_address]))