0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC用チートシート_Python

Posted at

序に 意図と現状

既存の解説記事がバラけており煩雑なのでこれ1枚で全部まとめます。QlitaとMarkdownの初学も兼ねています。
私が思い出せなかったことや知らなかったことだけ書きます。
何もかもを端折るので初学者向きの記事にはならないと思われますが、公開しながら作ればモチベにもなるので時間をかけて充実させていきたいと思います。満足したらC++とRubyでも書きます。
完全に筆者の自分用。AtCoderのコンテストに特化しています。
先駆者の先輩方、暇で暇で仕方ない方がもしいらっしゃいましたら助言や載せるべき話題をコメントいただけると嬉しいです。

第1章 演算子 

Now loading...

第n章 配列(イテラブルオブジェクト)

基礎

intro_list.py
ex =

pprint ~ デバッグ用出力モジュール

intro_list.py
ex =

str ~ 文字列

intro_list.py

ex = input() #標準入力の受け取りはすべて文字列型

ex2 = list(ex) #1文字ずつにバラされリスト化する、変更するなら必須
ex3 = ''.join(ex2) #元に戻す逆操作、''内に結合ワードを入れる

range ~ for文のオトモ?

intro_list.py
s

list ~ 基本配列

intro_list.py
ex = [] #初期化
ex.append("要素") #要素追加
ex.insert() #第1引数:

# 重要:演算子 = や * で複製したリストは同一のものを参照しているだけなので、個別上書きは不可。
from copy import deepcopy
ex2 = ex.copy
ex3 = deepcopy(ex)
[[] for _ in range(5)]  # 二次元配列の作成
# (×) [[]] * 5

tuple ~ 不変

intro_set.py
ex = tuple() #初期化、listの追加不可

set ~ 重複不許容

intro_set.py
ex = set() #初期化、listなど(更新可能オブジェクト)は追加不可
set.add("要素") #要素の追加

# 重要:型が違っても値が同じなら等価とみなされ消える(True == 1、False == 0)
s = {1, 1.0, True}
print(s) # >> {1}

dict ~ 辞書

intro_set.py
ex = {} #定義
ex[key] == "要素1","要素2" #要素追加

generator ~ リスト内包表記

intro_set.py

第n章 コンストラクタによる演算

総和計算 sum(iterable,start=0)

intro_set.py
iterable = [1,2,3,4]  #数値群から成る配列
sum(iterable,start=0) #第2引数start:計算結果に加算する数値、省略可

# 重要:sumifは存在しないので、条件付き総和の計算はリストを作り直す
print(sum([i for i in iterable if i % 2 == 1])
# >> 4

第n章 実用

4.1 Grid (行列) 問題

4.1.1 基礎

N行M列のグリッドが与えられるとする。
i行目 j列目の要素は、grid [ i ][ j ]で取得。↓、→方向の順で探索を行う。
変数として、i → row(行)、j → col(列) が用いられる。

.py

4.1.2 行列の回転(ABC404B - Grid Rotation)

.py

4.2 素因数分解

素数テーブル生成「エラトステネスの篩」

テンプレート

.py
iterable = [1,2,3,4]  #数値群から成る配列
sum(iterable,start=0) #第2引数start:計算結果に加算する数値、省略可

# 重要:sumifは存在しないので、条件付き総和の計算はリストを作り直す
print(sum([i for i in iterable if i % 2 == 1])
# >> 4

終章 まだ使えてないけど役立ちそうなもののメモ

sympy ~ 代数計算ライブラリ

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?