['a','b']と['c','d']の全組み合わせを取り、それらの文字列を結合したリストを作製したい
上の例では['ab', 'ac', 'bc', 'bd']の新たなリストを得たい
python3
1import itertools 2 3list_out = ['a','b'] 4list_in = ['c','d'] 5 6combination_ = list(itertools.product(list_out, list_in)) 7 8print(combination_) 9join_ = ''.join(combination_)
実行結果はこうなります。
[('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd')] Traceback (most recent call last): File "mol_combination.py", line 11, in <module> join_ = ''.join(combination) TypeError: sequence item 0: expected str instance, tuple found
各リスト内で文字列を結合するにはどうすれば良いでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。