Question: Solve the following problems with PYTHON. 1- Tuples: Suppose S is a set of integers, e.g. {4,2, 1, 2, 5, 0}. Write a function 'three_tuples'

Solve the following problems with PYTHON.

1- Tuples: Suppose S is a set of integers, e.g. {4,2, 1, 2, 5, 0}. Write a function 'three_tuples' that includes a triple comprehension and returns a list of all three element tuples (i, j, k) such that i, j, k are elements of S whose sum is zero.

2- Dictionaries: Conceptually, a dictionary is a set of key-value pairs. The syntax for specifying a dictionary in terms of its key-value pairs resembles the syntax for setsit uses curly bracesexcept that instead of listing the elements of the set, one lists the key-value pairs. In this syntax, each key-value pair is written using colon notation: key : value

a) Write a function 'dict_init' to initialize the following dictionary: mydict = {'Neo':'Keanu', 'Morpheus':'Laurence', 'Trinity':'Carrie-Anne'}

b) Suppose dlist is a list of dictionaries and k is a key. Write a function 'dict_find' that receives dlist and k, and uses a comprehension to return a list whose ith element is the value corresponding to key k in the ith dictionary in dlist. If a dictionary does not contain k as one of its keys, use 'NOT PRESENT' for that dictionary.

3- File reading: Write a function 'file_line_count' to open a file and return the number of lines that it has. Try out your function on stories_small.txt.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!