Guest User

Untitled

a guest
Jan 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. # import the itertools
  2. import itertools
  3.  
  4. # Declaring the list geek
  5. n_lst = [[1, 2], [3, 4], [5, 6]]
  6.  
  7. # chain.from_iterable() function returns the elements of nested list
  8. # and iterate from first list of iterable till the last
  9. # end of the list
  10.  
  11. lst = list(itertools.chain.from_iterable(n_lst))
  12. print(lst) # [1, 2, 3, 4, 5, 6]
  13.  
  14. 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