nozayasu-memo

プログラムのメモ

python

pyenvとpipenvによる環境構築

僕は業務上、開発と環境構築をrubyとpythonのどちらもやります。 そのためrubyだとこうでpythonだとこうと、頭の切り替えがよく起きるのです。 rubyとpythonの行き来する上で、操作感覚が似ていることはとても助かります。 pyenvのおかげで、rbenvと似た感覚…

more_itertools chunkedの処理を読む

実際のコードは以下 def chunked(iterable, n): """Break *iterable* into lists of length *n*: >>> list(chunked([1, 2, 3, 4, 5, 6], 3)) [[1, 2, 3], [4, 5, 6]] If the length of *iterable* is not evenly divisible by *n*, the last returned list w…

more_itertoolsでリストを小分けにする

大きめIDのリストを一定量の塊に分解しながら、DBに問い合わせをして後続の処理とかをしたいケースがあった そんな時にmore_itertoolsを使ったら読みやすくなったという話 結果から、more_itertoolsのchunkedを使うと次のような書き方ができる >>> from more…