2
3

More than 1 year has passed since last update.

pythonでdequeの中身を出力するには`*dq`とすればOK

Last updated at Posted at 2022-01-31

pythonでdequeの中身を出力するには*dqとすればOK

test.py
from collections import deque

L = deque()
L.append("a")
L.append("b")
L.append("c")

# deque 1つの場合
print(*(L))

L2 = deque()
L2.append("d")
L2.append("e")
L2.append("f")

# deque 2つ足す場合
print(*(L + L2))

# 上記だと、なぜか空白が一緒にprint()されるので、、、文字列にして空白を削除する
str = "".join(list(L + L2))
print(str)

実行

$ python test.py 
a b c
a b c d e f
abcdef

参考

2
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3