0

Given two lists, the objective is to find the non-overlapping value between them.

Based on the suggestion discussed in OP. This can be achieved either of the two approach

list_one=['ISL','BUK','ORG','CLC','STS','PLP','t1','t2','t3','t4','DE1','DE2','DE4']
list_two=['t1','t2','t3','t4']

APP1=set(list_one) ^ set(list_two)

APP2 = set(list_one).symmetric_difference(list_two)

Both suggestion outputted

{'DE4', 'DE2', 'CLC', 'STS', 'ORG', 'BUK', 'ISL', 'DE1', 'PLP'}

While this work, but the order from list_one is distorted. My question is, how can the above code be modified to output as below, where, the ordering follow as per in list_one

EXPECTED_OUTPUT=['ISL','BUK','ORG','CLC','STS','PLP','DE1','DE2','DE4']
mpx
  • 3,081
  • 2
  • 26
  • 56
  • Sorry, I guess that isn't a proper duplicate. But maybe https://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-whilst-preserving-order helps you? – Karl Knechtel Oct 14 '20 at 09:59

1 Answers1

1
inner_set = set(list_one) & set(list_two)
EXPECTED_OUTPUT = [i for i in list_one + list_two if i not in inner_set]

# or
EXPECTED_OUTPUT = [i for i in list_one + list_two if not (i in list_one and i in list_two)]
辜乘风
  • 152
  • 5