xxxxxxxxxx
list1 = ["Hello ", "take "]
list2 = ["Dear", "Sir"]
resList = [x+y for x in list1 for y in list2]
print(resList)
#['Hello Dear', 'Hello Sir', 'take Dear', 'take Sir']
xxxxxxxxxx
a = [1, 2, 3]
b = [4, 5]
# method 1:
c = a + b # forms a new list with all elements
print(c) # [1, 2, 3, 4, 5]
# method 2:
a.extend(b) # adds the elements of b into list a
print(a) # [1, 2, 3, 4, 5]
xxxxxxxxxx
list1 = [1, 2, 3]
list2 = [4, 5, 6]
concatenated_list = list1 + list2
print(concatenated_list)
xxxxxxxxxx
#plz susciibe to my youtube channel -->
#https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A
list1 = [1,2,3,4,5,6]
list2 = [7,8,9,10,11,12]
numbers_list = list1 + list2
print(numbers_list)
xxxxxxxxxx
sum([[1, 2, 3], [4, 5, 6], [7], [8, 9]],[])
# [1, 2, 3, 4, 5, 6, 7, 8, 9]
xxxxxxxxxx
>>> l1 = [1, 2, 3]
>>> l2 = [4, 5, 6]
>>> joined_list = [*l1, *l2] # unpack both iterables in a list literal
>>> print(joined_list)
[1, 2, 3, 4, 5, 6]
xxxxxxxxxx
list1 = ["M", "na", "i", "Ke"]
list2 = ["y", "me", "s", "lly"]
list3 = [i + j for i, j in zip(list1, list2)]
print(list3)
# My name is Kelly
xxxxxxxxxx
>>> t1 = ['a', 'b', 'c']
>>> t2 = ['d', 'e']
>>> t1.extend(t2)
>>> print(t1)
['a', 'b', 'c', 'd', 'e']
xxxxxxxxxx
""" There are 3 methods: '+', list.append, list.extend() """
# '+'
list_one = [11, 12, 13]
list_two = [14, 15, 16]
answer = list_one + list_two
--> answer: [11,12,13,14,15,16]
# 'list.append' adds items indivudually
# WARNING it treats a list as 1 item
first_list = [1, 2, 3, 4, 5]
second_list = [6, 7, 8, 9]
first_list.append(second_list)
--> first_list: [1, 2, 3, 4, 5, [6, 7, 8, 9]]
# 'extend' adds to the end, only works when both are lists
first_list = [1, 2, 3, 4, 5]
second_list = [6, 7, 8, 9]
first_list.extend(second_list)
--> first_list: [1, 2, 3, 4, 5, 6, 7, 8, 9]