Sets

Although in Python the set doesn't receive as much attention as its popular cousin the list, sets play an important role in analytics, so we include them here. To make a set, we use the built-in set() function. There are three things you need to know about sets:

  • They are immutable
  • They are unordered
  • The elements of a set are unique

Therefore, sets in Python are very similar to their mathematical counterparts if you are familiar with the basic set theory. The set methods also duplicate typical set operations and include union(), intersection(), add(), and remove(). These functions come in handy when wanting to perform typical set-like operations on data structures, such as lists or tuples, following conversions to sets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset