# Iteratively extending a list

Is there a way to collapse multiple_get into as few lines as possible?

def single_get(target):
return [some list of objects] # might be an empty list

def multiple_get(targets):
result = []
for target in targets:
result.extend(single_get(target))
return result

• This code looks a bit sketchy. Please fill it in with real code so that we can advise you properly. – 200_success Jun 12 '16 at 5:29

Look into the itertools library in general, for list-and-sequence-manipulating commands. You're looking for a way to "flatten" a list of lists; itertools calls this itertools.chain.
def multiple_get(targets):

def multiple_get(targets):

• If you prefer functional programming style to list comprehensions, you could also use itertools.chain(map(single_get, target)). – David Foerster Jun 12 '16 at 9:36