Python Set intersection()

Python’s set.intersection(sets) creates and returns a new set consisting of the elements that are members of all sets – this and the set argument(s). The resulting set has at most as many elements as any other set given in the argument list. Here’s a minimal example that creates a new set arising from the intersection … Read more

How to Check if a Key Exists in a Python Dictionary?

Summary: To check whether a key exists in a dictionary, you can use: The in keyword The keys() method The get() method The has_key() method Overview Mastering dictionaries is one of the things that differentiates the expert coders from the intermediate coders. Why? Because dictionaries in Python have many excellent properties in terms of runtime—and … Read more

Are Python Lambda Functions All Greek To You?

Learn to Love Your Lambda! Lambda functions in python are simple one-line functions without a name (and therefore called an anonymous function) that can take many arguments but will only evaluate a single expression. They’re fast, short, and simple and can help you write cleaner ‘more pythonic’ code. If like me you wanted to learn … Read more