THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
Suppose you have two lists and output a single list by joining or appending multiple lists.
Each element is appended to the end of the new list.
Let’s create a list of sub-list or two-dimensional lists in python.
one = [1, 2,3,4]
two=[5,6,7,8,9]
After joining the list, the result is
[1, 2, 3, 4, 5, 6,7,8,9]
There are multiple ways to join or append a list
Syntax:
one+two
or one+=two
Here is an example
one = [1, 2,3,4]
two=[5,6,7,8,9]
result=one+two
print(result)
Here is an example
one = [1, 2,3,4]
two=[5,6,7,8,9]
result=[]
result.extend(one)
result.extend(two)
print(result)
one.extend(two)
print(one)
import operator
one = [1, 2,3,4]
two=[5,6,7,8,9]
result = operator.add(one, two)
print(result)
unpack and extract individual elements and join using square bracket syntax
Here is an example
one = [1, 2,3,4]
two=[5,6,7,8,9]
result = [*one, *two]
print(result)
🧮 Tags
Recent posts
Puppeteer Login Test example How to convert Double to Integer or Integer to double in Dart| Flutter By Example Best ways to fix 504 gateway time out in nodejs Applications Fix for Error No configuration provided for scss Multiple ways to List containers in a Docker with examplesRelated posts