Answers for "array to set python"

1

convert array to set python

# Simple example:

list_ex = [1, 2, 3, 4]
list_set = set(list_ex)

# Printing the newly-created set should yield the following result:
# {1, 2, 3, 4}

# If you have a matrix (list of lists), you can convert 
# it to a set by following this example:
matrix_ex = [[1, 2], [3, 4], [5, 6]]
matrix_set = {e for l in matrix_ex for e in l}
Posted by: Guest on July-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language