Question: 14. Use Python. Modify the comprehension, dist = [{'James':'Sean', 'director':'Terence'}, {'James':'Roger', 'director':'Lewis'}, {'James':'Pierce', 'director':'Roger'}] k = 'James', to handle the case in which k might
14. Use Python. Modify the comprehension, dist = [{'James':'Sean', 'director':'Terence'}, {'James':'Roger', 'director':'Lewis'}, {'James':'Pierce', 'director':'Roger'}] k = 'James', to handle the case in which k might not appear in all the dictionaries. The comprehension evaluates to the list whose i-th element is the value corresponding to key k in the ith dictionary in dlist if that dictionary contains that key, and 'NOT PRESENT' otherwise. Test your comprehension with k = 'Bilbo' and k = 'Frodo' and with the following list of dictionaries:dlist = [{'Bilbo':'Ian','Frodo':'Elijah'}, {'Bilbo':'Martin','Thorin':'Richard'}].
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
