xxxxxxxxxx
listone = [1,2,3]
listtwo = [4,5,6]
joinedlist = listone + listtwo
xxxxxxxxxx
x = [["a","b"], ["c"]]
result = sum(x, [])
# This combines the lists within the list into a single list
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
#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
>>> 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
""" 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]
xxxxxxxxxx
data1 = [1, 2, 3]
data2 = [4, 5, 6]
data = data1 + data2
print(data)
# output : [1, 2, 3, 4, 5, 6]
xxxxxxxxxx
listone = [1, 2, 3]
listtwo = [4, 5, 6]
joinedlist = listone + listtwo
xxxxxxxxxx
#define lists
my_list = ["a", "b"]
other_list = [1, 2]
#extend my_list by adding all the values from other_list into my list
my_list.extend(other_list)
# output: ['a', 'b', 1, 2]