def decode_imdata(imdata):
    """Given a sequence of pixels, returns an iterator of characters
    encoded in the image"""
imdata = iter(imdata)
while True:
    pixels = list(imdata.next()[:3] + imdata.next()[:3] + imdata.next()[:3])
byte = 0
for c in range(7):
    byte |= pixels[c] & 1
byte <<= 1
byte |= pixels[7] & 1
yield chr(byte)
if pixels[-1] & 1:
    break
Стеганография в Python — Stepic