0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonの小技

Last updated at Posted at 2021-04-30

配列操作

a = ['aaa', 'bbb', 'ccc', 'ddd']

# 改行分割
res = '\n'.join(a)
出力結果
aaa
bbb
ccc
ddd

前後に任意の文字を連結する

res = ['pre_' + item + '_apre' for item in a]
出力結果
#['pre_aaa_apre', 'pre_bbb_apre', 'pre_ccc_apre', 'pre_ddd_apre']

ブランク連結

res = ' '.join(a)
出力結果
# aaa bbb ccc ddd

【zip + f】の大技

a = ['aaa', 'bbb', 'ccc', 'ddd']
b = ['J', 'P', 'K']
for i, j in zip(a,b):
    print(f'{i} : {j}')
出力結果
aaa : J
bbb : P
ccc : K

pip upgrade 失敗時

 curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

pickleの話(save/load)機械学習にも使われています。

0
1
2

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?