compare - How to find all elements when comparing two lists? -
import counter import collections import itertools, collections list1=[('1234', '5678', 9101112, 131415, 161716, 19), ('1234', '5678', 9101112, 131415, 161716, 19), ('1723113685', '1958120268', 704338729, 1310973186, 38760, 80), ('1723113685', '1958120268', 704338729, 1310973186, 38760, 70), ('1234', '5678', 9101112, 131415, 161716, 19), ('19216813', '6311624397', 3851697578, 0, 58816, 80), ('6311624397', '19216813', 2747564191, 3851697579, 890, 58816), ('19216813', '6311624397', 3851697579, 2747564192, 58816, 80), ('1234', '5678', 9101112, 131415, 161716, 19), ('19216813', '6311624397', 3851698039, 2747565640, 58816, 50)] list2=[('1723113685', '1958120268', 704338729, 1310984130, 38760, 80), ('1723113685', '1958120268', 704338729, 1310985498, 38760, 80), ('1723113685', '1958120268', 704338729, 1310986866, 38760, 80), ('1723113685', '1958120268', 704338729, 1310973186, 38760, 80), ('6311624397', '19216813', 2747564192, 3851697579, 80, 58816), ('19216813', '6311624397', 3851698039, 2747564192, 58816, 80), ('19216813', '6311624397', 3851698039, 2747565640, 58816, 80), ('1234', '5678', 9101112, 131415, 161716, 19), ('19216813', '6311624397', 3851698039, 2747568536, 58816, 80), ('19216813', '6311624397', 3851698039, 2747569984, 58816, 80), ('19216813', '6311624397', 3851698039, 2747571432, 58816, 80), ('19216813', '6311624397', 3851698039, 2747572880, 58816, 80)] ab=[] abdict = counter(ab) x in list1: if x in list2: ab.append(x) key, value in abdict.items(): if value>2: print key
i want find matched elements between list1
, list2
. when change list1
, list2
counter, not find element, shows match 1 element.
this displays elements, can't find how many elements.
go through list1 , check if element contains in list2 , override equals/hashcode method in class list holds.
list<classa> list1 = [a1, a2]; list<classa> list2 = [a3, a4]; list<classa> matchedelement = new arraylist<classa>(); (classa a: list1) { if (list2.contains(a)){ matchedelement.add(a); } } system.out.println(matchedelement); public class classa { @override public boolean equals(object obj) { //compare objects values } @override public int hashcode() { final int prime = 31; int result = 1; result = prime * result + obj.hashcode(); }
Comments
Post a Comment