Data Structure Conversions

This lesson highlights the main ways of converting one data structure to another.

The principle of conversion between built-in data structures in Python is similar to that of Python’s primitive data types.

Explicit Conversion

The template for explicitly converting from one data structure to another is as follows:

destination_structure_name(source_structure_object)

destination_structure_name is the name of the data structure that we want to convert to.

source_structure_object is the object which we want to convert.

Converting to a List

We can convert a tuple, set, or dictionary to a list using the list() constructor. In the case of a dictionary, only the keys will be converted to a list.

Get hands-on with 1200+ tech skills courses.