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
関連記事
pyplt.scatter を使って散布グラフを描くことができる。 点の色は、点ごとに変えることができる。 下の例では color の配列で点の色を指定している。 例 from matplotlib …
matplotlib で2種類のcsvファイルをプロットする方法
data1.csv と、data2.csv の2つのファイルを散布図としてプロットするには次のようにする。 例 import numpy as np from matplotlib import py …
集合にモノを付け足して和集合を作るには、|= 演算子を使う。(python では、集合(set)を波かっこで囲んで表す。) 例 a = {‘東京’} b = {‘大阪’,’千葉’} c = a | b …
matplotlib の ax でx軸、y軸の端の値を設定する
axes には、set_xlim として定義する。 例 import numpy as np from matplotlib import pyplot as plt x = np.linspace( …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。