teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

追記

2019/10/26 10:54

投稿

quickquip
quickquip

スコア11314

answer CHANGED
@@ -60,4 +60,39 @@
60
60
  )
61
61
  )
62
62
  )
63
+ ```
64
+
65
+ ----
66
+
67
+ そういうケースがありうるならどちらかというと
68
+ ```python
69
+ from itertools import product
70
+
71
+ A = ('a', 'b', 'c')
72
+ B = ('a', 'b', 'c','d','e')
73
+ C = ('d', 'e')
74
+
75
+ [q for q in product(A, B, C) if len(q) == len(set(q))]
76
+ ```
77
+ と解決するべきではないでしょうか。
78
+
79
+ ```
80
+ [('a', 'b', 'd'),
81
+ ('a', 'b', 'e'),
82
+ ('a', 'c', 'd'),
83
+ ('a', 'c', 'e'),
84
+ ('a', 'd', 'e'),
85
+ ('a', 'e', 'd'),
86
+ ('b', 'a', 'd'),
87
+ ('b', 'a', 'e'),
88
+ ('b', 'c', 'd'),
89
+ ('b', 'c', 'e'),
90
+ ('b', 'd', 'e'),
91
+ ('b', 'e', 'd'),
92
+ ('c', 'a', 'd'),
93
+ ('c', 'a', 'e'),
94
+ ('c', 'b', 'd'),
95
+ ('c', 'b', 'e'),
96
+ ('c', 'd', 'e'),
97
+ ('c', 'e', 'd')]
63
98
  ```

2

些細

2019/10/26 10:54

投稿

quickquip
quickquip

スコア11314

answer CHANGED
@@ -39,7 +39,7 @@
39
39
 
40
40
 
41
41
  ----
42
- 以下あまりにも読めにくいので回答として取り消します
42
+ 以下あまりにも読めにくいので回答として取り消します
43
43
 
44
44
  ```python
45
45
  from itertools import chain, permutations, product

1

追記

2019/10/26 02:16

投稿

quickquip
quickquip

スコア11314

answer CHANGED
@@ -22,14 +22,27 @@
22
22
 
23
23
  対称性を重んじるなら
24
24
  ```python
25
- [x + y for x, y in product(permutations('abc', 2), permutations('de', 1))]
25
+ [x + y for x, y in product(permutations('abc', 2), permutations('de', 1))]
26
26
  ```
27
27
 
28
28
  ---
29
29
 
30
30
  連結を増やせるように `for x, y`を排除すると
31
+
31
32
  ```python
32
33
  from itertools import chain, permutations, product
34
+ [tuple(chain.from_iterable(q)) for q in product(permutations('abc', 2), permutations('de', 1))]
35
+ ```
36
+
37
+
38
+ (`('a', 'b', 'c')`は`'abc'`に省略してます)
39
+
40
+
41
+ ----
42
+ 以下あまりにも読めにくいので回答として取り消します
43
+
44
+ ```python
45
+ from itertools import chain, permutations, product
33
46
  list(map(tuple, map(chain.from_iterable, product(permutations('abc', 2), permutations('de', 1)))))
34
47
  ```
35
48
 
@@ -47,7 +60,4 @@
47
60
  )
48
61
  )
49
62
  )
50
- ```
63
+ ```
51
-
52
-
53
- (`('a', 'b', 'c')`は`'abc'`に省略してます)