-
Notifications
You must be signed in to change notification settings - Fork 0
/
duplicate_items_function.py
62 lines (37 loc) · 1.02 KB
/
duplicate_items_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
"""duplicate_items_function.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/13oOpgQf6GQDzp9Vhxcrq9EoOELbMObW5
**Method 1**
"""
from collections import Counter
def DuplicateItemsAre(items):
test_set=set()
d=list()
for item in items :
k=len(test_set)
test_set.add(item)
t=len(test_set)
if k==t :
d.append(item)
duplicate_items=Counter(d)
for item in duplicate_items:
print(item,"appears " ,duplicate_items.get(item)+1,"times")
"""**Method** **2**
"""
from collections import Counter
def DuplicateItems(items):
test_set=set()
d=list()
counts={}
for i in items :
k=len(test_set)
test_set.add((i))
t=len(test_set)
if k==t :
counts[i]=items.count(i)
return counts
L=["osama","osama",1,2,3,3,1,2,5,5,8,8,1,1]
DuplicateItems(L)
DuplicateItemsAre(L)