回答編集履歴
2
追記
answer
CHANGED
@@ -14,4 +14,22 @@
|
|
14
14
|
|
15
15
|
with open("output.txt",'w') as file:
|
16
16
|
file.writelines(strs)
|
17
|
+
```
|
18
|
+
|
19
|
+
## 追記
|
20
|
+
単語間にスペースを入れるときはリストの要素ごとに単語のリストを作って、単語間にスペース区切りを入れる方法があります。
|
21
|
+
```python
|
22
|
+
import itertools
|
23
|
+
|
24
|
+
lists = [['a', 'b', 'c'], ['e', 'f', 'g']]
|
25
|
+
print(lists)
|
26
|
+
|
27
|
+
# リストの要素ごとに文字をつなげる
|
28
|
+
# strs = ['abc', 'efg']
|
29
|
+
strs = [''.join(lists[i]) for i in range(len(lists)) ]
|
30
|
+
|
31
|
+
with open("output.txt", 'w') as file:
|
32
|
+
# リストの要素をスペースで区切って文字列として表示
|
33
|
+
file.writelines(' '.join(strs) )
|
34
|
+
|
17
35
|
```
|
1
追記
answer
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
itertools.chain.from_iterableでリストを1次元配列に変換してから1文字ずつ文字列に追加して、一つの文字列として扱えば[]や,は出力されません。
|
2
|
+
|
1
3
|
```python
|
2
4
|
import itertools
|
3
5
|
|