set集合,是一个无序且不重复的元素集合

  1 class set(object):
  2     """
  3     set() -> new empty set object
  4     set(iterable) -> new set object
  5      
  6     Build an unordered collection of unique elements.
  7     """
  8     def add(self, *args, **kwargs): # real signature unknown
  9         """
 10         Add an element to a set,添加元素
 11          
 12         This has no effect if the element is already present.
 13         """
 14         pass
 15  
 16     def clear(self, *args, **kwargs): # real signature unknown
 17         """ Remove all elements from this set. 清除内容"""
 18         pass
 19  
 20     def copy(self, *args, **kwargs): # real signature unknown
 21         """ Return a shallow copy of a set. 浅拷贝  """
 22         pass
 23  
 24     def difference(self, *args, **kwargs): # real signature unknown
 25         """
 26         Return the difference of two or more sets as a new set. A中存在,B中不存在
 27          
 28         (i.e. all elements that are in this set but not the others.)
 29         """
 30         pass
 31  
 32     def difference_update(self, *args, **kwargs): # real signature unknown
 33         """ Remove all elements of another set from this set.  从当前集合中删除和B中相同的元素"""
 34         pass
 35  
 36     def discard(self, *args, **kwargs): # real signature unknown
 37         """
 38         Remove an element from a set if it is a member.
 39          
 40         If the element is not a member, do nothing. 移除指定元素,不存在不保错
 41         """
 42         pass
 43  
 44     def intersection(self, *args, **kwargs): # real signature unknown
 45         """
 46         Return the intersection of two sets as a new set. 交集
 47          
 48         (i.e. all elements that are in both sets.)
 49         """
 50         pass
 51  
 52     def intersection_update(self, *args, **kwargs): # real signature unknown
 53         """ Update a set with the intersection of itself and another.  取交集并更更新到A中 """
 54         pass
 55  
 56     def isdisjoint(self, *args, **kwargs): # real signature unknown
 57         """ Return True if two sets have a null intersection.  如果没有交集,返回True,否则返回False"""
 58         pass
 59  
 60     def issubset(self, *args, **kwargs): # real signature unknown
 61         """ Report whether another set contains this set.  是否是子序列"""
 62         pass
 63  
 64     def issuperset(self, *args, **kwargs): # real signature unknown
 65         """ Report whether this set contains another set. 是否是父序列"""
 66         pass
 67  
 68     def pop(self, *args, **kwargs): # real signature unknown
 69         """
 70         Remove and return an arbitrary set element.
 71         Raises KeyError if the set is empty. 移除元素
 72         """
 73         pass
 74  
 75     def remove(self, *args, **kwargs): # real signature unknown
 76         """
 77         Remove an element from a set; it must be a member.
 78          
 79         If the element is not a member, raise a KeyError. 移除指定元素,不存在保错
 80         """
 81         pass
 82  
 83     def symmetric_difference(self, *args, **kwargs): # real signature unknown
 84         """
 85         Return the symmetric difference of two sets as a new set.  对称差集
 86          
 87         (i.e. all elements that are in exactly one of the sets.)
 88         """
 89         pass
 90  
 91     def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
 92         """ Update a set with the symmetric difference of itself and another. 对称差集,并更新到a中 """
 93         pass
 94  
 95     def union(self, *args, **kwargs): # real signature unknown
 96         """
 97         Return the union of sets as a new set.  并集
 98          
 99         (i.e. all elements that are in either set.)
100         """
101         pass
102  
103     def update(self, *args, **kwargs): # real signature unknown
104         """ Update a set with the union of itself and others. 更新 """
105         pass
时间: 2024-10-12 12:44:12

set集合,是一个无序且不重复的元素集合的相关文章

set集合(set是一个无序且不重复的元素集合)

功能: 一.可以去掉列表,元组中的重复项 二.可以求交集,合集,差集等 def add(self, *args, **kwargs): """ 添加 """ s1 = (1,2,3,4,2,3,1)s3 = set(s1)s4 = s3.add(5)print(s1)print(s3)print(s4)(1, 2, 3, 4, 2, 3, 1){1, 2, 3, 4, 5}None def clear(self, *args, **kwargs)

Python封装函数:实现删除一个list里面的重复,且元素顺序要与原list顺序对应

封装函数:实现删除一个list里面的重复,且元素顺序要与原list顺序对应 代码:def info(l):l1 = l[:]for i in range(len(l)):v = l.count(l[i])if l1.count(l[i]) > 1:for j in range(1, v):l1.remove(l[i])return l1 print(info([1, 2, 3, 4, 2, 3, 6, 2])) 思想:统计相同元素出现的次数,然后删除到1 原文地址:http://blog.51c

用集合写一个简单的随机分组,以及集合内元素数量查询

12个人,随机分为4组 public static void main(String[] args) { List list = new ArrayList(); List list1 = new ArrayList(); List list2 = new ArrayList(); List list3 = new ArrayList(); Random ran = new Random(); for (int i = 1; i <= 12; i++) { list.add(i);//集合添加元

从头认识Spring-1.16 SpEl对集合的操作(2)-查询集合以及投影元素集合

这一章节我们来讨论一下查询集合以及投影元素集合. 我们下面用一个例子说明上面的这两个部分. 1.domain 蛋糕类:(不变) package com.raylee.my_new_spring.my_new_spring.ch01.topic_1_21; public class Cake { private String name = ""; private double size = 0; public String getName() { return name; } publi

Key-Value是用一个不可重复的key集合对应可重复的value集合

Key-Value是用一个不可重复的key集合对应可重复的value集合.(典型的例子是字典:通过页码的key值找字的value值). 例子: key1-value1; key2-value2; key3-value3. SortedMap:如果一个Map可以根据key值排序,则称其为SortedMap.(如字典) !!注意数组和集合的区别:数组中只能存简单数据类型.Collection接口和Map接口只能存对象. 1 package TomTexts; 2 3 4 public class T

Python代码实现删除一个list里面的重复元素

方法一:是利用map的fromkeys来自动过滤重复值,map是基于hash的,大数组的时候应该会比排序快点吧 方法二:是用set(),set是定义集合的,无序,非重复 方法三:是排序后,倒着扫描,遇到已有的元素删之 ============================================================ #!/usr/bin/python#coding=utf-8'''Created on 2012-2-22Q: 给定一个列表,去掉其重复的元素,并输出'''de

JavaSE中Collection集合框架学习笔记(2)——拒绝重复内容的Set和支持队列操作的Queue

前言:俗话说“金三银四铜五”,不知道我要在这段时间找工作会不会很艰难.不管了,工作三年之后就当给自己放个暑假. 面试当中Collection(集合)是基础重点.我在网上看了几篇讲Collection的文章,大多都是以罗列记忆点的形式书写的,没有谈论实现细节和逻辑原理.作为个人笔记无可厚非,但是并不利于他人学习.希望能通过这种比较“费劲”的讲解,帮助我自己.也帮助读者们更好地学习Java.掌握Java. 无论你跟我一样需要应聘,还是说在校学生学习Java基础,都对入门和进一步启发学习有所帮助.(关

Java基础知识强化之集合框架笔记27:ArrayList集合练习之去除ArrayList集合中的重复字符串元素

1. 去除ArrayList集合中的重复字符串元素(字符串内容相同) 分析: (1)创建集合对象 (2)添加多个字符串元素(包含重复的) (3)创建新的集合 (4)遍历旧集合,获取得到每一个元素 (5)拿着个元素到新集合中去找,看有没有   有:不搭理它 没有:添加到新集合      (6)遍历新集合 2. 案例代码: 1 package cn.itcast_04; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 6

Python3基础 set() 删除一个列表中的重复项

镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.------------------------------------------ code: #创建具有重复元素的列表 list1=list([1,2,3,4,5,5,6,6,6]) #将列表转成集合,重复的元素自动消除 set1=set(list1) #将元素转为列表 list1=list(set1) print(list1) #大合集,你看得懂吗,好看吗? 还是上面