-2

I'm eager to know is there any way to join tow or more lists into one?

Please help me with this.

li= ["v1", "v2", "v3"]
l2= [1,2,3]
print(joined_list)
gm03
  • 49
  • 1
  • 4

1 Answers1

0

You can append two or more lists into one list by using the methods below.

  • Using "+" operator Example:
li1= ["v1","v2","v3"]
li2= [1,2,3]
joined_list= li1+li2
print(joined_list)

output:

['v1', 'v2', 'v3', 1, 2, 3]
  • Using list append function Example:
joined_list= []
li1= ["v1","v2","v3"]
li2= [1,2,3]

joined_list.append(li1)
joined_list.append(li2)

print(joined_list)

Output:

[['v1', 'v2', 'v3'], [1, 2, 3]]
  • You can also use list extend function.

The parameters should be only iterables.

Example:

joined_list= []
li1= ["v1","v2","v3"]
li2= [1,2,3]

joined_list.extend(li1)
joined_list.extend(li2)

print(joined_list)

Output:

['v1', 'v2', 'v3', 1, 2, 3]
Gowdham V
  • 574
  • 3
  • 4