LoginSignup
0
0

More than 1 year has passed since last update.

shuffle()の使い方

Posted at

リストをランダムに並び替えることができるメゾット
→「shuffle()」を利用する

ランダム関数 import randomで、ランダム変数を読み込む。そして、リストに格納。
list = ['a','b','c']
listをシャッフルするために、random.shuffle(list)でシャッフル。
そして、書き出すために、print(list)で書き出す。

image.png

■実行結果

['b', 'c', 'a']
['c', 'a', 'b']
['c', 'a', 'b']

実行を繰り返すと、a,b,cの順序が入れ替わる。

0
0
0

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
  3. You can use dark theme
What you can do with signing up
0
0