Comparison between lists (I couldn't do it on my own because of the different shapes of the lists)

Asked 1 years ago, Updated 1 years ago, 296 views

Please forgive me if there are some things that may not be achieved because I am a beginner.

If you print, you will see two lists as follows:

print(list1)
[['A', 'B', 'C', ['B', 'C', ['C', 'D']]]

print(list2)
['C', 'D']
["A", "B", "D"]
["A", "C", "F"]

List1 is a two-dimensional list, and list2 is a new line with multiple lists.

I want to compare list2 and list1 and remove duplicates from list2 (first list is between first list)
I would like the results to be as follows.
['D']
['A', 'D']
['A', 'F']

python

2023-01-22 20:01

1 Answers

list1 = [['A', 'B', 'C', ['B', 'C', ['C', 'D']]
list2 = [['C', 'D', ['A', 'B', 'D', ['A', 'C', 'F']]

list_diff = [[*({*l2}-{*l1})] for l1, l2 in zip (list1, list2)]
print(list_diff)

# [[['D'], ['A', 'D'], ['A', 'F']]


2023-01-22 21:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.