Skip to content

Commit

Permalink
Merge pull request dostonnabotov#11 from agilarasu/main
Browse files Browse the repository at this point in the history
Add Python snippet
  • Loading branch information
dostonnabotov authored Dec 29, 2024
2 parents afae80d + a035aed commit 55e8268
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions public/data/python.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@
"tags": ["python", "list", "flatten", "utility"],
"author": "technoph1le"
},
{
"title": "Flatten Unevenly Nested Lists",
"description": "Converts unevenly nested lists of any depth into a single flat list.",
"code": [
"def flatten(nested_list):",
" \"\"\"",
" Flattens unevenly nested lists of any depth into a single flat list.",
" \"\"\"",
" for item in nested_list:",
" if isinstance(item, list):",
" yield from flatten(item)",
" else:",
" yield item",
"",
"# Usage:",
"nested_list = [1, [2, [3, 4]], 5]",
"flattened = list(flatten(nested_list))",
"print(flattened) # Output: [1, 2, 3, 4, 5]"
],
"tags": ["python", "list", "flattening", "nested-lists", "depth", "utilities"],
"author": "agilarasu"
},
{
"title": "Remove Duplicates",
"description": "Removes duplicate elements from a list while maintaining order.",
Expand Down

0 comments on commit 55e8268

Please sign in to comment.