Home > Backend Development > Python Tutorial > How to convert list to set in python

How to convert list to set in python

(*-*)浩
Release: 2019-07-09 10:30:31
Original
17041 people have browsed it

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])
Copy after login

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)
Copy after login

The result is as follows:

(1,2,3,4)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template