In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to use the set function in Python, the content is very detailed, interested friends can refer to, hope to be helpful to you.
The set collection function is mainly used to remove repetition:
For example, if a list has multiple duplicate values, you can get rid of it with set
> l = [1, 2, 3, 4, 5, 4, 4, 3, 21]
> > >
> > l
[1, 2, 3, 4, 5, 4, 3, 21]
> > >
> > >
Set (l)
Set ([1,2,3,4,5,21])
> > >
Set can do intersection, union and subtraction.
Addition, deletion and modification of set
Zeng: > a = set ([1Jing 2Jing 3Jing 4])
> > a
Set ([1,2,3,4])
> > >
> a.add ('alex')
> > a
Set ([1,2,3,4, 'alex'])
Delete: > a.remove ('alex')
> > a
Set ([1,2,3,4])
> > >
Add multiple items: > b = set ([1, 2, 7, 8])
> > b
Set ([8,1,2,7])
> > a.update (b)
> > a
Set ([1,2,3,4,7,8])
Determine whether b is included in a
> > a
Set ([1,2,3,4,7,8])
> > b
Set ([8,1,2,7])
> > >
> > b.issubset (a)
True
The "unordered" set in python is relative to other set implemented with balanced binary trees, such as set in C++ using red-black trees and orderedset in python.
Set access operations based on balanced binary tree are all O (lgn) time, but because of the characteristics of binary search tree, it is easy to find the precursor and successor nodes of any node, so it can be regarded as "orderly".
The set in python is implemented based on hash table, and the access time can be regarded as O (1), but there is no way to efficiently complete sequence-related operations (such as finding precursors and successors, maximum and minimum values, etc.), so it is considered to be "unordered".
On how to use the set function in Python to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Net time\ ad.service-IP / set / ynet stop w32timenet start w32time
© 2024 shulou.com SLNews company. All rights reserved.