technology logo
technology logo

Set() and List() Function using Python

share link

by Abdul Rawoof A R dot icon Updated: Jan 31, 2023

Guide Kit Guide Kit  

Python’s set() function creates a new set object, i.e., an unordered collection of unique elements. Sets are commonly used for tasks such as: 

  • Removing duplicates from a list or other iterable. 
  • Checking for an element’s presence in a collection is more efficient than using a list or tuple, because sets are implemented using a hash table. 
  • Performing mathematical set operations such as union, intersection, and difference. 

Python’s list() function creates a new list object from an existing iterable, such as tuple, string, or another list. It is also used to convert other objects, such as a range or an iterator, into a list. list() also have other uses: 

  • You can also use the list() function to convert a string into a list of characters. 
  • You can also use the list() function to convert a range object into a list. 
  • You can also use the list() function to create an empty list. 

In general, the list() function is useful for converting other types of iterable objects, such as tuples, strings, or ranges, into a list, so that they can be manipulated with the full range of list methods and operators. 

 You may have a look at the code given below for set() and list() function using Python.