1. 获取两个list 的交集
# -*- coding=utf-8 -*-
#方法一:
a=[2,3,4,5]
b=[2,5,8]
tmp = [val for val in a if val in b]
print tmp
#[2, 5]
#方法二
print list(set(a).intersection(set(b)))
2. 获取两个...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sample2
{
class Program
{
static void Main(string[] ar...
假设我们现在有两个文件 a.txt 、b.txt
a.txt 中的内容如下:
a
c
1
3
d
4
b.txt 中的内容如下:
a
b
e
2
1
5
# Example 01
计算并集:
[root@VM_81_181_centos ~]# sort -u a.txt b.txt
1
2
3
4
5
a
b
c
d
e
[r...
有两个表 ,表a ,表b ,
create table a { age int , name varchar(20) } ending=innodb;
insert into a values(13,cen);
insert into a values(18,yue);
create table b { age int , name varchar(20...
var set1 = new Set([1,2,3]);var set2 = new Set([2,3,4]);
并集let union = new Set([...set1, ...set2]);
交集let intersect = new Set([...set1].filter( x => set2.has(x)));
差集let difference = new S...
题目:
给定两个数组,编写一个函数来计算它们的交集。
Given two arrays, write a function to compute their intersection.
示例 1:
输入: nums1 = [1,2,2,1], nums2 = [2,2]
输出: [2,2]
示例 2:
输入: nums1...