2

For example i know in Python you can append a list to list.

list = [a,b,c]

list += [d,e,f]

print(list)

[a,b,c,d,e,f]

Is there a way to accomplish this is list comprehension. I know we can define a list based on element, but is there a way to create a new list with list comprehension where i am define a segment of the list each iteration. Ie.

list = [function_that_returns_a_list(var) for var in vars]
  • List comprehension should be used when useful not because we must always use it – Pitto Sep 18 '19 at 19:08
  • 1
    are you trying to [flatten a nested list](https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists)? – pault Sep 18 '19 at 19:10
  • in list comprehension you can add single element to list - ie. `d` - but not list - `[d,e,f]` . You would have to use second `for` to add every element from `[d,e,f]` to main list. – furas Sep 18 '19 at 19:24

0 Answers0