Get difference between two lists in Python

Pubblicato il: 24 ottobre 2022
sul canale di: 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!


In questa pagina del sito puoi guardare il video online Get difference between two lists in Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato ExplainHowToSimply 24 ottobre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 321 volte e gli è piaciuto 9 spettatori. Buona visione!