Tuesday, December 29, 2020

Sets

Sets in python

Sets are unordered and unique and are denoted by {}.

Sets differ from dictionaries because sets don't have key-value pair.

my_set={}  //will declare a dictionary

my_set=set()  //use set function to declare a set

Some methods in sets:

my_set1= {1,2,3,4,5}

my_set2=  {3,4,5,6,7}

my_set1.union(my_set2) // gives all the numbers from both sets

{1,2,3,4,5,6,7} 

 my_set1.intersection(my_set2) //gives common elements in both sets.

 {3,4,5}

 my_set1-my_set2 // returns all elements in my_set1 that are not in  my_set2.

 

No comments:

Post a Comment

Anaconda Installation

In this post we will discuss about Anaconda and its installation. Anaconda comes with number of applications(jupyter notebook included), dat...