Skip to content

Commit 185ce93

Browse files
committed
Day 3: convert a list to a unique list
1 parent 35d2d6c commit 185ce93

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Day 3/__init__.py

Whitespace-only changes.

Day 3/complex_way.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Its time complexity is O(n)
2+
3+
def unique_list(input_list):
4+
unique = []
5+
for item in input_list:
6+
if item not in unique:
7+
unique.append(item)
8+
return unique
9+
10+
11+
print(unique_list([1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 5]))

Day 3/unique_list.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Write a Python function that takes a list
3+
and returns a new list with unique elements
4+
of the first list.
5+
"""
6+
7+
8+
def unique_list(input_list):
9+
return list(set(input_list))
10+
11+
12+
print(unique_list([1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 5]))

0 commit comments

Comments
 (0)