When I try CheckIO(http://www.checkio.org/), I couldn’t find a good way to count duplicate elements of a list. lst = [1, 3, 3, 4, 4, 5] lst.count(3) >>2 print [x for x in lst if lst.count(x) > 1] >>[3, 3, 4,…
Crayon Syntax Highlighter
WordPressのプラグイン”Crayon Syntax Highlighter“を入れてみた。 http://social-window.com/wp-plugin-crayon-syntax-highlighter/ ブログのコードがだいぶ読みやすくなった!
Git: merge
The following push command is to push “master” branch to remote “origin” repository. git push origin master But this merge command is to merge master branch of “local” repository. git merge origin/master It’s troublesom. 🙁 To avoid mistakes,…
Python: itertools.takewhile
from itertools import takewhile from itertools import count def count_up(start, step, stop): return takewhile(lambda x: x < stop, count(start, step)) print list(count_up(1, 3, 10)) # >>[1, 4, 7] print list(count_up(1, 6, 30)) # >>[1, 7, 13, 19, 25] https://gist.github.com/aminami1127/2e92331b71fedc1b6d47 By…
Python: itertools.count
By itertools.count, we can easily create count up generateor. def count_up(start, stop, step): cnt = itertools.count(start, step) for i in cnt: if i > stop: break: else: yield i print list(count_up(1, 10, 2)) >>[1, 3, 5, 7, 9] https://gist.github.com/aminami1127/e0e29b94ead611fd65f3
Python: functools.partial
Pythonを勉強中のため、日々自分用の技術メモを書いていこうと思います。 I’m studying python, and I try to write daily technical memo for myself. functools.partialについて学習しました。 I learned functools.partial today. partialを使うと簡単に関数の部分適用が行えます。 import functools import math #paramter PI and radius #引数として円周率と半径を受け取り、面積を返す circle_squre = lambda pi, r: pi * r * r #円周率の値をpartialによって3に束縛した関数…