Last active
August 29, 2015 14:20
-
-
Save puhitaku/cda43b99abf1e82be3e5 to your computer and use it in GitHub Desktop.
One-liners in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#文字数を各文字ごとに数えてタプルのリストで返す | |
#Count characters and return the result with list of tuples. | |
#e.x. c('bbaaac') = [('a', 3), ('b', 2), ('c', 1)] | |
count = lambda s: [(c,s.lower().count(c)) for c in sorted(set(s.lower()))] | |
#6ケタのHEXを3つのDECのリストにして返す | |
#Convert 6 digits HEX in 3 decimals and return tuple. | |
#e.x. d('0099CC') = [0, 153, 204] | |
hexcol = lambda h: [int(h[i:i+2],16) for i in range(0, len(h), 2)] | |
#RLE (Run Length Encoding) | |
from functools import reduce | |
from itertools import groupby() | |
from operator import add | |
rle = lambda s: reduce(add, [str(len(list(g)))+k for k,g in groupby(s)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment