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 でcsv ファイルを読み込むとき、最初の行をスキップする方法
numpy の loadtxt で読み込む行を省略したい場合 スキップしたい行を # 等の記号でコメントアウトして、 loadtxt の comments = ‘#’ とすると …
matplotlib で、x軸・y軸の目盛りを反対方向につけたい場合。
デフォルトでは、x軸はグラフの下に、y軸は左側につけられる。 例 import numpy as np from matplotlib import pyplot as plt x = np.lins …
matplotlib でグラフ表示ウィンドウの画面上の位置を自由に設定する方法
matplotlib.use(‘TkAgg’) としておき、 get_current_fig_manager().window.wm_geometry(“+20+50”) として、(+20+50)のと …
文字に tex の記法を使って数式を入力することもできる。 例 import numpy as np from matplotlib import pyplot as plt x = np.linsp …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。