Skip to content

Commit 55e8268

Browse files
authored
Merge pull request #11 from agilarasu/main
Add Python snippet
2 parents afae80d + a035aed commit 55e8268

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

public/data/python.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@
4848
"tags": ["python", "list", "flatten", "utility"],
4949
"author": "technoph1le"
5050
},
51+
{
52+
"title": "Flatten Unevenly Nested Lists",
53+
"description": "Converts unevenly nested lists of any depth into a single flat list.",
54+
"code": [
55+
"def flatten(nested_list):",
56+
" \"\"\"",
57+
" Flattens unevenly nested lists of any depth into a single flat list.",
58+
" \"\"\"",
59+
" for item in nested_list:",
60+
" if isinstance(item, list):",
61+
" yield from flatten(item)",
62+
" else:",
63+
" yield item",
64+
"",
65+
"# Usage:",
66+
"nested_list = [1, [2, [3, 4]], 5]",
67+
"flattened = list(flatten(nested_list))",
68+
"print(flattened) # Output: [1, 2, 3, 4, 5]"
69+
],
70+
"tags": ["python", "list", "flattening", "nested-lists", "depth", "utilities"],
71+
"author": "agilarasu"
72+
},
5173
{
5274
"title": "Remove Duplicates",
5375
"description": "Removes duplicate elements from a list while maintaining order.",

0 commit comments

Comments
 (0)