Flatten-List
Wed 12 November 2025
def flatten(nested_list):
flat_list = []
for item in nested_list:
if isinstance(item, list):
flat_list.extend(flatten(item))
else:
flat_list.append(item)
return flat_list
# Example usage
print(flatten([1, [2, 3], [4, [5, 6]]])) # [1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
# Check if a List is Sorted
def is_sorted(lst):
return lst == sorted(lst)
# Example usage
print(is_sorted([1, 2, 3, 4])) # True
print(is_sorted([4, 3, 2, 1])) # False
True
False
Score: 5
Category: python-basics