VOOZH about

URL: https://www.geeksforgeeks.org/python/time-complexity-to-convert-a-set-to-list-in-python/

⇱ Time Complexity to Convert a Set to List in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Time Complexity to Convert a Set to List in Python

Last Updated : 23 Jul, 2025

Concerting a set to a list involves iterating through the elements of the set and adding them to a list. The time complexity of this operation is linear and depends on the size of the set. Let's denote the size of the set as n. The time complexity to convert a set to a list generally takes O(n) time. where n is the n of elements in the set. There are various methods to convert a set to a list in Python. In this article, we will learn about the time complexity of different ways to convert a set to a list in Python.

Time Complexity to Convert a Set to List in Python

Below are some of the ways by which we can convert a set to a list in Python in different time complexity scenarios in Python:

Using list() constructor

In this method, we are going to use an in-built list() constructor which converts a set to a list directly. we have nothing to do with the constructor just call it and pass the set to it.


Output
List is: [1, 2, 3, 4, 5]
Small Set to List Time: 2e-05

Large Set to List Time: 0.0148

Using extend() method

The extend() method use to add the specified list elements (or any iterable) to the end of the current list. so in this method we are going to use this in-built provided functionality of the list.


Output
List is : [1, 2, 3, 4, 5]
Small Set to List Time in sec: 0.0

Large Set to List Time in sec: 0.011127

Using List Comprehension

List comprehension is the short way for doing a task. And we can also use list comprehension for conversion of list to set. In this method we are iterating through the set and inserting the element of set to a list.


Output
Newly Created list : [1, 2, 3, 4, 5]
Small Set to List Time: 0.0

Large Set to List Time: 0.02328

Conclusion

The time complexity of this operation is O(n), where n is the number of elements in the set. Each element in the set needs to be added to the list, and this process takes linear time.

Comment
Article Tags: