Question: need help with 3. in the easiest way possible code to 1 and 2. def common_strings(list1, list2): temp = [i for i in list1 if
need help with 3. in the easiest way possible
code to 1 and 2.
def common_strings(list1, list2): temp = [i for i in list1 if i in list2] return temp def my_diff(list1, list2): temp = [i for i in list1 if i not in list2] temp += [i for i in list2 if i not in list1] return temp if __name__ == '__main__': list1 = ['B', 'A', 'C'] list2 = ['C', 'B', 'D'] print("Common : ", common_strings(list1, list2)) print("Difference : ", my_diff(list1, list2))Output :
Common : ['B', 'C'] Difference : ['A', 'D']
symbol 1:
PIH FLWS FCCY SRCE VNEt tWOU JOBS CAFd EgHt AVHI SHLm AAON ABAX ABEO ABEOW ABIL ABmd AXAS ACIA ACtg ACHC ACAd ACSt AXdX XLRN ANCX ARAY OILd OILU VXdN VXUP ACRX ACEt AKAO ACHN ACIW ACRS ACNB ACOR ACtS ACPW AtVI ACtA ACUR ACXm AdmS AdmP AdAP AdUS AEY IOtS AdmA AdBE AdtN AdRO AAAP AdES AEIS AItP Amd AdXS AdXSW AdVm mAUI YPRO AEgR AEgN AgLE AEHR AmtX AEPI AERI AVAV AEZS AEmd AFmd AgEN AgRX AgYS AgIO AgFS AgFSW AImt AIRm AIRt AtSg AIRg AmCN AIXg AKAm AKtX AKBA AKER AKRX ALRm ALSK AmRI ABdC AdHd ALdR
Symbol 2
IOtS AdmA AdBE AdtN AdRO AAAP AdES AEIS AItP Amd AdXS AdXSW AdVm mAUI YPRO AEgR AEgN AgLE AEHR AmtX AEPI AERI AVAV AEZS AEmd AFmd AgEN AgRX AgYS AgIO AgFS AgFSW AImt AIRm AIRt AtSg AIRg AmCN AIXg AKAm AKtX AKBA AKER AKRX ALRm ALSK AmRI ABdC AdHd ALdR ALdX ALXN ALCO ALgN ALIm ALJJ ALKS ABtX ALgt AIQ AHgP ARLP AHPI AmOt ALQA ALLt mdRX AFAm ALNY AOSL gOOg gOOgL SmCP AtEC ASPS AImC AmAg AmRN AmRK AYA AmZN AmBC AmBCW AmBA AmCX dOX AmdA AmEd UHAL AtAX AmOV AAL AgNC AgNCB AgNCP mtgE mtgEP ACSF ACAS AEtI
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 doesn't 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 first question, could you write another function to get the difference, ie, find 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 definitely different algorithms to implement such diff function, please choose a more efficient algorithm if possible. def my_diff( list1, list2): 3. As we know, each public company has a symbol for its stock trading in the financial market. For instance, AAPL is the symbol for Apple Inc., GOOG is the symbol for the company Google etc. Here we have two files symbols 1.txt and symbols2.txt, each file contains many symbols of public companies in Nasdaq. Please write a program to read these two files, use your my_diff function in the question 2 to find out the difference, you can either save the results to file/files 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
