Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge multiple lists into one list in python? [duplicate]

People also ask

How do you join multiple lists?

Using + operator The + operator does a straight forward job of joining the lists together. We just apply the operator between the name of the lists and the final result is stored in the bigger list. The sequence of the elements in the lists are preserved.

How do you merge two lists without duplicates in Python?

Python merges two lists without duplicates could be accomplished by using a set. And use the + operator to merge it.


import itertools
ab = itertools.chain(['it'], ['was'], ['annoying'])
list(ab)

Just another method....


Just add them:

['it'] + ['was'] + ['annoying']

You should read the Python tutorial to learn basic info like this.


a = ['it']
b = ['was']
c = ['annoying']

a.extend(b)
a.extend(c)

# a now equals ['it', 'was', 'annoying']