Skip to content

Commit 3fec4f9

Browse files
authored
Initial
common_element_in_list
1 parent 88c1caa commit 3fec4f9

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

common_element_in_list

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def common_elements(list1,list2):
2+
common = []
3+
count=0
4+
for i in list1:
5+
for j in list2:
6+
if(i==j):
7+
common.append(i)
8+
count=count+1
9+
print(common)
10+
print("Common elements in both list is : ",count)
11+
12+
def common_elements_dict(list1,list2):
13+
dict1={}
14+
for element in list2:
15+
dict1[element]=1
16+
count=0
17+
for i in list1:
18+
if dict1.get(i)!=None:
19+
print(i)
20+
count=count+1
21+
print("Number of elements common are: ", count)
22+
23+
24+
25+
26+
27+
l1=[2,4,6,8,10,12,14]
28+
l2=[3,6,9,12,15,18]
29+
common_elements_dict(l1,l2)

0 commit comments

Comments
 (0)