Created
June 29, 2021 07:38
-
-
Save PythonDotLand/d495f713798cfb3c37950b57d562a912 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> # Calculate all profucs of an input | |
| >>> list(itertools.product('abc', repeat=2)) | |
| [('a', 'a'), ('a', 'b'), ('a', 'c'), | |
| ('b', 'a'), ('b', 'b'), ('b', 'c'), | |
| ('c', 'a'), ('c', 'b'), ('c', 'c')] | |
| >>> # Calculate all permutations | |
| >>> list(itertools.permutations('abc')) | |
| [('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c'), | |
| ('b', 'c', 'a'), ('c', 'a', 'b'), ('c', 'b', 'a')] | |
| >>> # Take elements for iterator as long as predicate is True | |
| >>> list(itertools.takewhile(lambda x: x<5, [1,4,6,4,1])) | |
| [1, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment