
# Python code t get difference of two lists # Using set() def Diff(li1, li2): return list(set(li1) - set(li2)) + list(set(li2) - set(li1)) # Driver Code li1 = [10, 15, 20, 25, 30, 35, 40] li2 = [25, 40, 35] print(Diff(li1, li2))
I’ve also provided the Python source code to find the difference between two lists without using the set() method. This way you can easily compare both methods.
# Python code to get difference of two lists # Not using set() def Diff(li1, li2): li_dif = [i for i in li1 + li2 if i not in li1 or i not in li2] return li_dif # Driver Code li1 = [10, 15, 20, 25, 30, 35, 40] li2 = [25, 40, 35] li3 = Diff(li1, li2) print(li3)
If you have been searching for the right note-taking or knowledge management app, you have…
Looking for AnyType alternatives? You're not alone. AnyType has gained popularity as a privacy-focused, local-first…
Notion is a popular all-in-one workspace, but many users seek alternatives for different needs (free…
Logseq is a beloved tool in the personal knowledge management (PKM) community. It's free, open-source,…
Looking for a Webshare alternative? You're not alone. Webshare is a popular proxy service with…
Docker changed software development forever. It made containers accessible, gave developers a simple workflow, and…