Skip to content

Commit 7e7721d

Browse files
committed
daily commit 2024-05-01
1 parent f330029 commit 7e7721d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

2024-05-01/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Codecademy Recursive Flatten Funtion Project
2+
This is Recursive Flatten Function created in Codecademy "Learn Data Structures and Algorithms with Python" course.
3+
4+
Link to course: https://www.codecademy.com/enrolled/courses/learn-data-structures-and-algorithms-with-python

2024-05-01/flatten.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# define flatten() below...
2+
def flatten(my_list):
3+
result = []
4+
for item in my_list:
5+
if isinstance(item, list):
6+
print('List Found!')
7+
flat_list = flatten(item)
8+
for subitem in flat_list:
9+
result.append(subitem)
10+
continue
11+
result.append(item)
12+
return result
13+
14+
### reserve for testing...
15+
planets = ['mercury', 'venus', ['earth'], 'mars', [['jupiter', 'saturn']], 'uranus', ['neptune', 'pluto']]
16+
17+
print(flatten(planets))

0 commit comments

Comments
 (0)