【5秒でわかる】Pythonで配列の中身をシャッフルする(random.shuffle)

Python3

プログラム

import random
hoge = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(hoge)
random.shuffle(hoge)
print(hoge)

結果

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[5, 0, 8, 1, 7, 2, 6, 3, 9, 4]

解説

random.shuffle(array)
  1. array:シャッフルしたい配列

arrayをシャッフルしたうえで上書きします。

 

タイトルとURLをコピーしました

Fatal error: Uncaught JSMinException: Unterminated string literal. in /home/miyayamo/miyayamo.com/public_html/wp-content/plugins/cfiltering/lib/library/jsmin-php/jsmin.php:128 Stack trace: #0 /home/miyayamo/miyayamo.com/public_html/wp-content/plugins/cfiltering/lib/library/jsmin-php/jsmin.php(315): JSMin->action(1) #1 /home/miyayamo/miyayamo.com/public_html/wp-content/plugins/cfiltering/lib/library/jsmin-php/jsmin.php(76): JSMin->min() #2 /home/miyayamo/miyayamo.com/public_html/wp-content/plugins/yasakani-cache/yasakani-cache.php(570): JSMin::minify('<script type="a...') #3 /home/miyayamo/miyayamo.com/public_html/wp-content/plugins/yasakani-cache/yasakani-cache.php(925): Yasakani_setting::html_minify('<!doctype html>...', 1, 1, 1) #4 [internal function]: Yasakani_setting::output_cache('<!doctype html>...', 9) #5 /home/miyayamo/miyayamo.com/public_html/wp-includes/functions.php(4339): ob_end_flush() #6 /home/miyayamo/miyayamo.com/public_html/wp-includes/class-wp-hook.php(286): wp_ob_end_flush_all('') #7 /home/miyayamo/miya in /home/miyayamo/miyayamo.com/public_html/wp-content/plugins/cfiltering/lib/library/jsmin-php/jsmin.php on line 128