Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中列表/元组上的算术运算符?_Python_List_Tuples_Arithmetic Expressions - Fatal编程技术网

Python中列表/元组上的算术运算符?

Python中列表/元组上的算术运算符?,python,list,tuples,arithmetic-expressions,Python,List,Tuples,Arithmetic Expressions,我有两个类似的函数: object obj.getChild(childIndex) int obj.numChildren() children = obj.getChildren() children = [5,10,15,20,25] globalChildren = [1,2,3,4,5,6,7,8,9,10,12,14,16,18,20] difference = children - globalChildren difference = [15,25] shared = c

我有两个类似的函数:

object obj.getChild(childIndex)
int obj.numChildren()
children = obj.getChildren()
children = [5,10,15,20,25]

globalChildren = [1,2,3,4,5,6,7,8,9,10,12,14,16,18,20]

difference = children - globalChildren
difference = [15,25]

shared = children * globalChildren
shared = [5,10,20]
所以我用这些来创建这个函数:

collection obj.getChildren()
我在返回类型上很灵活,但是我会使用另一个列表来做很多“减法”、“乘法”。比如说:

object obj.getChild(childIndex)
int obj.numChildren()
children = obj.getChildren()
children = [5,10,15,20,25]

globalChildren = [1,2,3,4,5,6,7,8,9,10,12,14,16,18,20]

difference = children - globalChildren
difference = [15,25]

shared = children * globalChildren
shared = [5,10,20]
是否有一种快速而优雅的方法来完成这些任务,或者我必须逐个检查每个元素并手动收集这些元素?

您正在寻找

你在找我的朋友


谢谢,你能告诉我那些
{}
是什么收集类型吗?谢谢,你能告诉我那些
{}
是什么收集类型吗?