Skip to content

Instantly share code, notes, and snippets.

View kmerenkov's full-sized avatar

Konstantin Merenkov kmerenkov

  • Klarna
  • Berlin, Germany
View GitHub Profile
from itertools import takewhile, islice, cycle
# chunkify(xrange(1, 11), 2) => [[1,2], [3,4], [5,6], [7,8], [9,10]]
def chunkify(iterable, chunk_size):
_iterable = iter(iterable)
return takewhile(lambda x: x,
(list(islice(_iterable, chunk_size)) for _ in cycle([True])))
>>> import redis
>>> db = redis.Redis()
>>> db.flushall()
True
>>> db.set(u"фу".encode('utf-8'), u"бар".encode('utf-8'))
True
>>> db.keys('*')
['\xd1\x84\xd1\x83']
>>> print db.keys('*')[0].decode('utf-8')
фу