LoginSignup
0

More than 1 year has passed since last update.

iter()とnext()

Posted at

リストやタプルから1つずつ取り出す方法
for文とかでも書ける

リストやタプルをイテレータに変換

iter()

イテレータから一つずつ取り出す

next()
a = [1, 2, 3, 4]
a_iter = iter(a)

print(next(a_iter), next(a_iter), next(a_iter))
#1 2 3

a_next = next(a_iter)
print(a_next, a_next, a_next)
#1 1 1

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
What you can do with signing up
0