Replace-Negative

Wed 12 November 2025

def replace_negatives(lst):
    replaced = [x if x >= 0 else 0 for x in lst]
    print("List after Replacing Negatives:", replaced)

# Example usage
replace_negatives([-1, 2, -3, 4, -5])
List after Replacing Negatives: [0, 2, 0, 4, 0]
# intersection of a list 
def list_intersection(lst1, lst2):
    intersection = [x for x in lst1 if x in lst2]
    print("Intersection:", intersection)

# Example usage
list_intersection([1, 2, 3, 4], [3, 4, 5, 6])
Intersection: [3, 4]


Score: 5

Category: python-basics