Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.2 kB
2
Indexable
Never
def square_numbers(numbers):
    return [number ** 2 for number in numbers]

# Example usage:
numbers = [1, 2, 3, 4, 5]
squared_numbers = square_numbers(numbers)
print(squared_numbers)  # Output: [1, 4, 9, 16, 25]



def concatenate_lists(list1, list2):
    result = []
    for item1 in list1:
        for item2 in list2:
            result.append(item1 + item2)
    return result

# Example usage:
list1 = ["Hello ", "take "]
list2 = ["Dear", "Sir"]
concatenated_list = concatenate_lists(list1, list2)
print(concatenated_list)  # Output: ['Hello Dear', 'Hello Sir', 'take Dear', 'take Sir']



def remove_empty_strings(input_list):
    return input_list = list(filter(None, input_list))

# Example usage:
list1 = ["Mike", "", "Emma", "Kelly", "", "Brad"]
result = remove_empty_strings(list1)
print(result)  # Output: ['Mike', 'Emma', 'Kelly', 'Brad']



def display_lists(list1, list2):
    zipped_lists = zip(list1, list2[::-1])
    for item1, item2 in zipped_lists:
        print(f"{item1} {item2}")

# Example usage:
list1 = ["apple", "banana", "cherry"]
list2 = ["red", "yellow", "green"]
display_lists(list1, list2)
# Output:
# apple red
# banana yellow
# cherry green
Leave a Comment