0

Input for the lists:

input1 = ['A,B,C,D,E',
'"111","112","113","114","115"',
'"211","212","213","214","215"']

input2 = ['A,B,C,D,E',
'"111","112","113","114","115"',
'"211","212","213","214","215"',
'"311","312","313","314","315"',]

output = ['A,B,C,D,E',
'"111","112","113","114","115"',
'"211","212","213","214","215"',
'"311","312","313","314","315"',]

output should have all the entries out of the two...

for line1, line2 in zip(input1,input2):
    temp1 = line1.split(',')
    temp2 = line2.split(',')

In the above code both lists are of different lengths....also i want to iterate till the end of the longest list out of the two

I tried finding answers but couldnt so....

Rakesh
  • 81,458
  • 17
  • 76
  • 113

1 Answers1

0

It'd be more efficient to loop through the larger list and store each element into a hash table. Then loop through the second list and identify where the identity key matches a previous element. Print each one that found a duplicate. Your current method would have to loop through the list for each element causing a quadratic time complexity of O(n2), whereas using a hash table should get O(n*log(n)

Hash tables:

1.) https://www.tutorialspoint.com/python/python_hash_table.htm

2.) http://interactivepython.org/runestone/static/pythonds/SortSearch/Hashing.html

ca098
  • 68
  • 7