因为工作的原因,学习停滞了很久,也落后了很多。真的,学习坚持很重要,我们身边太多的诱惑,任何的困难都可能成为放弃的理由。让自己一直在行走,哪怕步子再小,只要走,就有希望。送给自己,死磕到底。
集合
集合是一个无序的,不重复的数据组合,它的主要作用如下:
去重,把一个列表变成集合,就自动去重了
关系测试,测试两组数据之前的交集、差集、并集等关系
变列表为集合
list_1 = [1,4,5,7,3,6,7,9] liset_1 = set(list_1) print(list_1,type(list_1)) >>>
[1, 4, 5, 7, 3, 6, 7, 9]
Process finished with exit cod
交集
list_1 = [1,4,5,7,3,6,7,9]
liset_1 = set(list_1)
list_2 = set([2,6,0,66,22,8,4])
print(list_1,list_2)
list_1.intersection(list_2)
print( list_1.intersection(list_2))
>>>
[4,6]
并集
list_1 = [1,4,5,7,3,6,7,9]
liset_1 = set(list_1)
list_2 = set([2,6,0,66,22,8,4])
print(list_1.union(list_2))
>>>
[0,1,2,3,4,5,6,7,66,9,8,22]
差集
list_1 = [1,4,5,7,3,6,7,9]
liset_1 = set(list_1)
list_2 = set([2,6,0,66,22,8,4])
print(list_1.difference(list_2))
>>>
[1,3,5,9,7]
子集
list_1 = [1,4,5,7,3,6,7,9]
liset_1 = set(list_1)
list_2 = set([2,6,0,66,22,8,4])
print(list_1.issubset(list_2))
>>>
false
父集
list_1 = [1,4,5,7,3,6,7,9]
liset_1 = set(list_1)
list_2 = set([2,6,0,66,22,8,4])
print(list_1.issuperset(list_2))
>>>
false
对称差集
list_1 = [1,4,5,7,3,6,7,9]
liset_1 = set(list_1)
list_2 = set([2,6,0,66,22,8,4])
print(list_1.issubset(list_2))
>>>
[0,1,2,66,3,5,7,9,22]
判断是没有交集
print("-----------")
list_3 = set([1,3,7])
list_4 = set([5,6,8])
print(list_3.isdisjoint(list_4))
>>>
true
当然,操作也可以用符号完成:
s = set([3,5,9,10]) #创建一个数值集合
t = set("Hello") #创建一个唯一字符的集合
a = t | s # t 和 s的并集
b = t & s # t 和 s的交集
c = t – s # 求差集(项在t中,但不在s中)
d = t ^ s # 对称差集(项在t或s中,但不会同时出现在二者中)
基本操作:
t.add('x') # 添加一项
s.update([10,37,42]) # 在s中添加多项
使用remove()可以删除一项:
t.remove('H')
len(s)
set 的长度
x in s
测试 x 是否是 s 的成员
x not in s
测试 x 是否不是 s 的成员
s.issubset(t)
s <= t
测试是否 s 中的每一个元素都在 t 中
s.issuperset(t)
s >= t
测试是否 t 中的每一个元素都在 s 中
s.union(t)
s | t
返回一个新的 set 包含 s 和 t 中的每一个元素
s.intersection(t)
s & t
返回一个新的 set 包含 s 和 t 中的公共元素
s.difference(t)
s - t
返回一个新的 set 包含 s 中有但是 t 中没有的元素
s.symmetric_difference(t)
s ^ t
返回一个新的 set 包含 s 和 t 中不重复的元素
s.copy()
返回 set “s”的一个浅复制
以上是python学习之路的详细内容。更多信息请关注PHP中文网其他相关文章!

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通过使用pyenv、venv和Anaconda来管理不同的Python版本。1)使用pyenv管理多个Python版本:安装pyenv,设置全局和本地版本。2)使用venv创建虚拟环境以隔离项目依赖。3)使用Anaconda管理数据科学项目中的Python版本。4)保留系统Python用于系统级任务。通过这些工具和策略,你可以有效地管理不同版本的Python,确保项目顺利运行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基于基于duetoc的iMplation,2)2)他们的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函数函数函数函数构成和稳定性构成和稳定性的操作,制造

数组的同质性对性能的影响是双重的:1)同质性允许编译器优化内存访问,提高性能;2)但限制了类型多样性,可能导致效率低下。总之,选择合适的数据结构至关重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,内存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

记事本++7.3.1
好用且免费的代码编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

WebStorm Mac版
好用的JavaScript开发工具