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

How to convert a list into a set in Python

Release: 2019-07-08 09:12:19
Original
4411 people have browsed it

How to convert a list into a set in Python

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.

set Syntax:

class set([iterable])

Parameter description:

iterable -- iterable object object;

Return value:

Return the 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 the Python Tutorial column Get studying!

The above is the detailed content of How to convert a list into a 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