Home  >  Article  >  Backend Development  >  How to convert list to set in python

How to convert list to set in python

(*-*)浩
(*-*)浩Original
2019-07-01 13:57:3116985browse

The set() function creates an unordered set of non-repeating elements, which can perform relationship testing, delete duplicate data, and calculate intersection, difference, union, etc.

How to convert list to set in python

set Syntax: (Recommended learning: Python video tutorial)

class set([iterable])

Parameter description :

iterable -- iterable object object;

Return value:

Returns a new collection object.

Convert the list to a set:

list1=[1,3,4,3,2,1]
 
list1=set(list1)
 
print(list1)

The result is as follows:

(1,2,3,4)

For more Python-related technical articles, please visit Python Tutorial column for learning!

The above is the detailed content of How to convert list to set in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:python loop functionNext article:python loop function