#要根据集合有的功能编写一个类
#自定义集合。模拟Python内置集合类型,实现元素添加、删除以及并集、交集、对称差集等基本运算。
请问这个具体怎么写呢
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
关注 ```python class Cuset: def __init__(self,seq): self._cuset = set(seq) def add(self,elem): self._cuset.add(elem) def remove(self,elem): self._cuset.remove(elem) def __str__(self): return "{0._cuset!s}".format(self) def __repr__(self): return "Cuset({0._cuset!r})".format(self) def update(self,*others):#并集 for new in others: self._cuset |= new._cuset def intersection_update(self,*others):#合集 for new in others: self._cuset &= new._cuset def difference_update(self,*others):#差集 for new in others: self._cuset -= new._cuset def symmetric_difference_update(self,other): self._cuset ^= other._cuset def clear(self): pass def pop(self): pass a=Cuset([1,2,3,4,555,6,6,67]) b=Cuset(["a","b","c"]) d=Cuset([66,88,99,100,100,]) a.update(b,d) print(a._cuset)
```
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用 1
悬赏问题
- ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
- ¥15 (标签-MATLAB|关键词-多址)
- ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
- ¥500 52810做蓝牙接受端
- ¥15 基于PLC的三轴机械手程序
- ¥15 多址通信方式的抗噪声性能和系统容量对比
- ¥15 winform的chart曲线生成时有凸起
- ¥15 msix packaging tool打包问题
- ¥15 finalshell节点的搭建代码和那个端口代码教程
- ¥15 Centos / PETSc / PETGEM