From 7ada7a90c2da0177bf22c16d00b8fc35ae503b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 13 Oct 2020 11:23:03 +0200 Subject: [PATCH] Combinatorics --- README.md | 25 ++++++++++++------------- index.html | 31 +++++++++++++++---------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index b8753f3..67843be 100644 --- a/README.md +++ b/README.md @@ -553,28 +553,27 @@ from itertools import product, combinations, combinations_with_replacement, perm ```python >>> product('ab', '12') -[('a', '1'), ('a', '2'), - ('b', '1'), ('b', '2')] +[('a', '1'), ('a', '2'), ('b', '1'), ('b', '2')] ``` ```python ->>> combinations('abc', 2) -[('a', 'b'), ('a', 'c'), - ('b', 'c')] +>>> combinations('abc', 2) # a b c +[('a', 'b'), ('a', 'c'), # a . x x + ('b', 'c')] # b . . x ``` ```python ->>> combinations_with_replacement('abc', 2) -[('a', 'a'), ('a', 'b'), ('a', 'c'), - ('b', 'b'), ('b', 'c'), - ('c', 'c')] +>>> combinations_with_replacement('abc', 2) # a b c +[('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x + ('b', 'b'), ('b', 'c'), # b . x x + ('c', 'c')] # c . . x ``` ```python ->>> permutations('abc', 2) -[('a', 'b'), ('a', 'c'), - ('b', 'a'), ('b', 'c'), - ('c', 'a'), ('c', 'b')] +>>> permutations('abc', 2) # a b c +[('a', 'b'), ('a', 'c'), # a . x x + ('b', 'a'), ('b', 'c'), # b x . x + ('c', 'a'), ('c', 'b')] # c x x . ``` diff --git a/index.html b/index.html index f445b96..fcc8441 100644 --- a/index.html +++ b/index.html @@ -632,22 +632,21 @@ shuffle(<list>) (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
>>> product('ab', '12')
-[('a', '1'), ('a', '2'),
- ('b', '1'), ('b', '2')]
-
-
>>> combinations('abc', 2)
-[('a', 'b'), ('a', 'c'),
- ('b', 'c')]
-
-
>>> combinations_with_replacement('abc', 2)
-[('a', 'a'), ('a', 'b'), ('a', 'c'),
- ('b', 'b'), ('b', 'c'),
- ('c', 'c')]
-
-
>>> permutations('abc', 2)
-[('a', 'b'), ('a', 'c'),
- ('b', 'a'), ('b', 'c'),
- ('c', 'a'), ('c', 'b')]
+[('a', '1'), ('a', '2'), ('b', '1'), ('b', '2')]
+
+
>>> combinations('abc', 2)                        #   a  b  c
+[('a', 'b'), ('a', 'c'),                          # a .  x  x
+ ('b', 'c')]                                      # b .  .  x
+
+
>>> combinations_with_replacement('abc', 2)       #   a  b  c
+[('a', 'a'), ('a', 'b'), ('a', 'c'),              # a x  x  x
+ ('b', 'b'), ('b', 'c'),                          # b .  x  x
+ ('c', 'c')]                                      # c .  .  x
+
+
>>> permutations('abc', 2)                        #   a  b  c
+[('a', 'b'), ('a', 'c'),                          # a .  x  x
+ ('b', 'a'), ('b', 'c'),                          # b x  .  x
+ ('c', 'a'), ('c', 'b')]                          # c x  x  .
 

#Datetime