📜  转换数组以设置 python 代码示例

📅  最后修改于: 2022-03-11 14:45:27.222000             🧑  作者: Mango

代码示例1
# 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}