python中list类型相减
两个list ()类型相减
就是比如
a=[1,2,3,4,5]
b=[2,3,4]
a-b需要得到[1,5]
但是python list 不支持减法
只能使用py的投机取巧了~ 呵呵
我们来用set() 如下
<code l=python >
print list (set(a)-set(b))
[1,5] #结果
两个list ()类型相减
就是比如
a=[1,2,3,4,5]
b=[2,3,4]
a-b需要得到[1,5]
但是python list 不支持减法
只能使用py的投机取巧了~ 呵呵
我们来用set() 如下
<code l=python >
print list (set(a)-set(b))
[1,5] #结果
暂无评论。
评论功能维护中,当前仅展示历史评论。