Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import the itertools
- import itertools
- # Declaring the list geek
- n_lst = [[1, 2], [3, 4], [5, 6]]
- # chain.from_iterable() function returns the elements of nested list
- # and iterate from first list of iterable till the last
- # end of the list
- lst = list(itertools.chain.from_iterable(n_lst))
- print(lst) # [1, 2, 3, 4, 5, 6]
- print [y for x in n_lst for y in x] # [1, 2, 3, 4, 5, 6]
Add Comment
Please, Sign In to add comment