Question: 1. Write a function common_strings which takes two lists of strings and returns a list of common strings. For example, list1 = [ B, A,C
1. Write a function common_strings which takes two lists of strings and returns a list of common strings. For example, list1 = [ B, A,C ], list2 = [ C, B, D ], your function should compare items in these two lists and return a new list = [ B, C ] ( the order doesnt matter ), because both String B and C are present in list1 and list2. Run some test cases to verify correctness of your function. def common_strings( list1, list2 ):
2. Based on the rst question, could you write another function to get the dierence, ie. nd all strings in list1 but not in list2, and all strings in list2 but not in list1? let us say L1 represents the list of all strings in list1 but not in list2, L2 represents the list of all strings in list2 but not in list1, you should return [ L1, L2 ] . There are denitely dierent algorithms to implement such di function, please choose a more ecient algorithm if possible. def my_di( list1, list2):
3. As we know, each public company has a symbol for its stock trading in the nancial market. For instance, AAPL is the symbol for Apple Inc., GOOG is the symbol for the company Google etc. Here we have two les symbols1.txt and symbols2.txt, each le contains many symbols of public companies in Nasdaq. Please write a program to read these two les, use your my_di function in the question 2 to nd out the dierence, you can either save the results to le/les or just print them out. Please convert each symbol to upper case before doing comparison.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
