回答編集履歴

1

2022/12/01 16:09

投稿

melian
melian

スコア19809

test CHANGED
@@ -1,12 +1,10 @@
1
- ※ 事前に [ordered-set · PyPI](https://pypi.org/project/ordered-set/) のインストールが必要。
2
1
  ```python
3
2
  from itertools import product
4
- from ordered_set import OrderedSet
5
3
  from pprint import pprint
6
4
 
7
5
  data = [['山田', '佐藤', '田中'], ['上野', '田中'], ['上野', '田中', '佐藤', '山田', '近藤'], ['田中', '近藤', '上野', '佐藤'], ['田中', '近藤']]
8
6
 
9
- result = [*map(list, [i for i in map(OrderedSet, product(*data)) if len(i) == len(data)])]
7
+ result = [list(i) for i in product(*data) if len(set(i)) == len(data)]
10
8
  pprint(result)
11
9
 
12
10
  # [['山田', '上野', '田中', '佐藤', '近藤'],