0
0

More than 3 years have passed since last update.

自分用のメモ python

Last updated at Posted at 2019-12-17

とりいそぎ

重み付きランダム選択

weight_random.py
import random
data = ["1","2","3"]
w = [5,3,2]
for i in range(10):
    print(random.choices(data,weight=w))
# result(期待値)
# "1":5回
# "2":3回
# "3":2回

自身が置いてあるディレクトリ名の取得

self_dir_name.py
import os,sys
print(os.path.dirname(sys.argv[0]))
# result
# C:\~~~

半角大文字英語と数字のリスト

alph_num.py
alph = [chr(i) for i in range(65, 65+26)]
num = [chr(i) for i in range(48,48+10)]
# result
# alph = ["A",...,"Z"]
# num = ["0",...,"9"]

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