How to combine two lists in Python

Sharing buttons:

in this video we're going to see how we

can combine two lists using Python so

let's imagine that we have two data

structures one representing people who

are already in my company in another

representing a subsidiary that I am

about to purchase in my original company

we will have Julia Eric and Dylan and in

my subsidiary we'll have Michael Eric

and Michael

there are a number of different ways

that I could do this depending on

whether I want to create new copies of

my data structure or not

if I would like to have a new data

structure with all of the members of my

company data structure plus all the

members of my subsidiary data structure

I can do this by concatenating the two

lists together using the addition

operator and we see here that this

produces a new data structure with Julia

Eric Dylan Michael Eric and Michael

if I'm dealing with very very large data

structures this might be very wasteful

both in terms of memory use and in terms

of CPU cycles spent moving data back and

forth a slightly more efficient way to

do this is to perform an operation in

place to modify my original company data

structure such that it contains all of

the members of my subsidiary we can do

this by using the extend method to find

on list objects in Python since this is

an in-place operation we'll see that

it's not returning anything to us but

when I look at the company data

structure we see that it has been

modified in place to contain all the

members from my subsidiary