Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
1
Indexable
Never
def add_lists(list1, list2):

    result = []

  
    min_length = min(len(list1), len(list2))

    
    for i in range(min_length):
        result.append(list1[i] + list2[i])
    if len(list1) > min_length:
        result.extend(list1[min_length:])
    elif len(list2) > min_length:
        result.extend(list2[min_length:])

    return result

list1 = ["M", "na", "i", "Ke"]
list2 = ["y", "me", "s", "lly"]


result_list = add_lists(list1, list2)

print("Resulting list:", result_list)


def square_list(lst):
    squared_list = [x**2 for x in lst]
    return squared_list


input_list = [1, 2, 3, 4, 5]
result = square_list(input_list)
print(result)

def concatenate_lists(list1, list2):
  
    concatenated_list = [x + y for x in list1 for y in list2]
    return concatenated_list

list1 = ["Hello ", "take "]
list2 = ["Dear", "Sir"]


result = concatenate_lists(list1, list2)
print(result)

def remove_empty_strings(lst):

    return list(filter(lambda x: x != "", lst))


list1 = ["Mike", "", "Emma", "Kelly", "", "Brad"]


result = remove_empty_strings(list1)
print(result)


def iterate_lists(list1, list2):
   
    for item1, item2 in zip(list1, reversed(list2)):
        print(item1, item2)


list1 = ["apple", "banana", "cherry"]
list2 = ["orange", "pear", "grape"]

iterate_lists(list1, list2)
Leave a Comment