Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the six operation schemes of collection types in Python dictionary?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What are the six operation schemes of collection types in the Python dictionary? many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Collection type

① uses the collection's factory methods set () and frozenset ():

> s = set ('cheeseshop') > s set ([' bookshop', 'bookshop']) > > t = frozenset (' bookshop') > t frozenset (['baked,' hacked, 'kink,' type,']) > > type (s) > type (t)

How ② updates a collection adds and removes members of the collection using various collection built-in methods and operators:

> s.add ('z') > s set (['cased,' estranged, 'hacked,' oiled, 'paired,' sworn,'z']) > > s.update ('pypi') > s set ([' clocked, 'estranged,' set, 'hogwash,' oval, 'pendant,' s.remove,'z']) > > s set (['c']) ) > > s-= set ('pypi') > s set ([' cased, 'estranged,' hacked, 'oval,' s'])

③ delete collection

Del s

④ membership (in, not in)

> s = set ('cheeseshop') > t = frozenset (' bookshop') >'k'in s False >'k'in t True >'c 'not in t True

⑤ set equivalence / non-equivalence

> s = = t False > s! = t True > u = frozenset (s) > s = = u True > set ('posh') = = set (' shop') True

⑥ difference complement / relative complement set (-) the difference complement or relative complement set of two sets (s and t) refers to a set C in which the elements belong only to the set s, not to

In the set t. There is an equivalent method for subtraction.

Difference (). > s-t set (['censor,' e'])

Symmetric difference (^): symmetric difference is the XOR of a set. The above article is the practical application step of the Python dictionary to the set type.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report