0

Please help.

>>> a = [7, 2, 2, 2, 3, 2]
>>> b = [2, 2, 2, 3, 3, 5]
Expected result:    [2, 7, 3, 5]

For a "Pictorial Presentation" , please see https://www.w3resource.com/python-exercises/python-basic-exercise-32.php

set is not allowed. collections is not allowed. Because I am trying to learn loops.

I have tried , without success, doing the opposite of some of the solutions found in Intersection of two lists including duplicates? Because that thread is trying to do the opposite of what I am trying to achieve.

Please also note this question is not the same question as: Python removing items from a list that exist in another list but keeping duplicates that aren't in that intersect nor Python intersection of two lists keeping duplicates nor Python: intersection of 2 lists keeping duplicates from both lists

Thank you very much.

goughgough
  • 91
  • 9

1 Answers1

1
c = list()
for x in a+b:
    if x not in c:
        c.append(x)
mujjiga
  • 16,186
  • 2
  • 33
  • 51
  • Thanks a million for your quick response, mujjiga. Short and sweet. Perhaps you could also simplify some of the solutions found in https://stackoverflow.com/questions/37645053/intersection-of-two-lists-including-duplicates They are too complicated for me to follow. I appreciate your help. – goughgough Mar 10 '19 at 22:09
  • @goughgough np :) Done added there :) – mujjiga Mar 10 '19 at 22:18
  • Thanks a million. I added a comment to your brilliantly simple to follow solution. This is without doubt the most elegant and easy and simple to follow solution. mujjiga you are a genius. I appreciate your help. – goughgough Mar 10 '19 at 22:59