Categories
Python Answers

How to do list subtraction operation with Python?

Spread the love

Sometimes, we want to do list subtraction operation with Python.

In this article, we’ll look at how to do list subtraction operation with Python.

How to do list subtraction operation with Python?

To do list subtraction operation with Python, we can use list comprehension.

For instance, we write

[item for item in x if item not in y]

to get the items in list x but not in list y with

item for item in x if item not in y

Conclusion

To do list subtraction operation with Python, we can use list comprehension.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *