Question: Python Please Task D.1: Assign to L the list consisting of the first five letters ['A', B' 'C,'D,'E']. Next, use L in an expression whose
Python Please
Task D.1: Assign to L the list consisting of the first five letters ['A', B' 'C,'D",'E']. Next, use L in an expression whose value is [(0, 'A), (1, 'B'), (2, 'C'), (3, 'D'), (4, 'E')] Your expression should use a range and a zip, but should not use a comprehension. Task D.2. Starting from the lists [10, 25, 40] and [1, 15, 20], write a comprehension whose value is the three-element list in which the first element is the sum of 10 and 1, the second is the sum of 25 and 15, and the third is the sum of 40 and 20. Your expression should use zip but not list. Task D.3. Suppose dlist is a list of dictionaries and k is a key that appears in all the dictionaries in dlist. Write a comprehension that evaluates to the list whose i-th element is the value corresponding to key k in the ith dictionary in dlist. Test your comprehension with some data. Here are some example data dlist = [{'James':'Sean','director','Terence'), {'James':'Roger', 'director':'Lewis'), {'James','Pierce', director' :'Roger')] k = 'James Task D.4. Modify the comprehension in D.3 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 d list = [{'Bilbo'lan','Frodo':'Elijah'), {'Bilbo': 'Martin','Thorin': 'Richard'}] Task D.5. Using range, write a comprehension whose value is a dictionary. The keys should be the integers from 0 to 99 and the value corresponding to a key should be the square of the key Task D.6. Assign some set to the variable D, e.g. D-fred','white','blue'. Now write a comprehension that evaluates to a dictionary that represents the identity function on D
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
