Question: this is a CS question using concept of dictionary, I am confused and need help in python, thanks! Write a function dct_op that takes in
this is a CS question using concept of dictionary, I am confused and need help in python, thanks!
Write a function dct_op that takes in a dictionary (the player's name (strings) as the key and a list of total game points (integers) as value) and a function func. Your function should apply function func to each integer in the list and return an updated dictionary. Assume the input func always takes in an integer and returns another integer. Note: You can solve this problem using one-line dictionary comprehensions in the format below. You are not required to but it is very similar to list comprehensions, so give it a try! This link might be helpful. {key:valuefor(key,value)initerable} Example: > example ={x:x+10 for x in [1,2,3,4,5]} >> print(example) {1:11,2:12,3:13,4:14,5:15} def update_stats(dct, func): "I" dct ={ 'Curry': [26,21,30], 'James': [26,22,18]} >> update_stats (dct, squared) \{'Curry': [676,441,900], 'James': [676,484,324]} dct ={ 'Poole': [15,11,27,23], 'Tatum': [35,21,22,28],\ 'Harden': [28,11,22,19]} > update_stats(dct, identity) \{'Poole': [15,11,27,23], 'Tatum': [35,21,22,28], 'Harden': [28,11,22,19]} > update_stats (dct, lambda x:x+1 ) \{'Poole': [16,12,28,24], 'Tatum': [36,22,23,29], 'Harden': [29,12,23,20]}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
