Set() and List() Function using Python

share link

by Abdul Rawoof A R dot icon Updated: Feb 10, 2024

technology logo
technology logo

Guide Kit Guide Kit  

Python’s set() function creates a new set object, i.e., an unordered collection of unique elements. People use sets for tasks such as:

  • Removing duplicates from a list or other iterable. 
  • Using a set to check for an element's presence in a collection is more efficient than using a list or tuple. This is due to the fact units use hash tables.
  • Performing mathematical set operations such as union, intersection, and difference. 

Python’s list() function creates a new list object from an existing iterable. The iterable could be a 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. 

Generally, you can use the list() function to convert other types of iterable objects into a list. You can use it with tuples, strings, or ranges. This allows you to manipulate them using all list methods and operators. 

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