next() を使う。
例
my_arr = ['春','夏','秋','冬'] my_iter = iter(my_arr) print(next(my_iter,'なし')) print(next(my_iter,'なし')) print(next(my_iter,'なし')) print(next(my_iter,'なし')) print(next(my_iter,'なし'))
結果
春 夏 秋 冬 なし
雑記
投稿日:2022年7月28日 更新日:
next() を使う。
my_arr = ['春','夏','秋','冬'] my_iter = iter(my_arr) print(next(my_iter,'なし')) print(next(my_iter,'なし')) print(next(my_iter,'なし')) print(next(my_iter,'なし')) print(next(my_iter,'なし'))
春 夏 秋 冬 なし
執筆者:seyanen
関連記事
matplotlib で、複数のグラフを簡単にプロットする方法
変数を並べて書くと、次のように自動的に順番を理解してグラフを表示してくれる。 例 import numpy as np from matplotlib import pyplot as plt fro …
凡例(legend)の表示位置を変更するには、axis の legend の loc を設定する。 次のリンクhttps://matplotlib.org/stable/api/_as_gen/mat …
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。
リストを iter に変えたあと、… next() を使う。 参考リンク https://www.programiz.com/python-programming/methods/buil …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。