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
関連記事
ファイルを開くとき、「a+」を指定することで、data.txt というファイルを書き込みモードで開く。(もしファイルが存在していなければ作成する。) 例 f = open(‘data.txt’, ‘a …
matplotlib で折れ線グラフの下部に色をつけて塗りつぶす方法
pyplot の fill_between を使う。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = & …
matplotlib で、グラフのタイトルに上付き文字を入力する方法
数学記号などで、グラフのタイトルに上付きの文字を入力したい場合がある。 その場合は次のように書いて設定できる。 例 import numpy as np from matplotlib import …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。