Get difference between two lists in Python

Veröffentlicht am: 24 Oktober 2022
auf dem Kanal: ExplainHowToSimply
321
9

This short Python tutorial shows how to get the difference, intersection and also the union of two lists. The video shows different options for the operation with a simple example. The first option uses list comprehension, the second uses set and the third option utilizes logical operators. The difference can be created with the following command:
[name for name in list1 if name not in list2]
list(set(list1).difference(set(list2)))

The union of two lists can be done with:
list(set(list1).union(set(list2)))
list(set(list1) | set(list2))
The intersection can be created with:
list(set(list1).intersection(set(list2)))

Many thanks for watching!


Auf dieser Seite können Sie das Online-Video Get difference between two lists in Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer ExplainHowToSimply 24 Oktober 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 321 Mal angesehen und es wurde von 9 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!