Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
Last active October 2, 2017 13:30
Show Gist options
  • Save stevedoyle/52b945dbc80242d190c57ce685e6f63c to your computer and use it in GitHub Desktop.
Save stevedoyle/52b945dbc80242d190c57ce685e6f63c to your computer and use it in GitHub Desktop.
itertools.chain
p = [(1,2,3), (2,4), (1,6)]
set(itertools.chain(*p))
=> {1,2,3,4,5,6}
where:
*p expands the list elements into separate arguments
itertools.chain() chains all of the individual elements of each parameter (the tuple from p in this case) into a single iterable stream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment