-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_duplicate.py
More file actions
43 lines (35 loc) · 1.05 KB
/
Copy pathremove_duplicate.py
File metadata and controls
43 lines (35 loc) · 1.05 KB
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
# Problem : Remove Duplicate from a list
# Method - 1 : Basic Approach
# numbers = [10,20,40,10,10,20,70,60,20,30,40,50]
# unique = []
# for num in numbers:
# if num not in unique:
# unique.append(num)
# print(sorted(unique))
# print(unique)
# Method - 2 : Functional Approach
# def remove_duplicate(numbers):
# unique = []
# for num in numbers:
# if num not in unique:
# unique.append(num)
# unique.sort()
# return unique
# numbers = [10,20,40,10,10,20,70,60,20,30,40,50]
# result = remove_duplicate(numbers)
# print(result)
# Method - 3 : oops
class remove_duplicate:
def __init__(self,numbers):
self.numbers = numbers
def check_list(self):
unique = []
for num in self.numbers:
if num not in unique:
unique.append(num)
unique.sort()
return unique
numbers = [10,20,40,10,10,20,70,60,20,30,40,50]
obj = remove_duplicate(numbers)
result = obj.check_list()
print(result)