Saturday, October 13, 2018

A Python email signature puzzle


By Vasudev Ram


[ UPDATE: I forgot to escape the less than and greater than signs in the code, so the code was a bit garbled.
Fixed now. My apologies to readers seeing the post twice as a result, via blog aggregators like Planet Python. ]

Hi, readers,

I sometimes use slightly cryptic Python code snippets in my email signature.

Can you figure out what output this Python program produces, and how it works, without running the code?
I folded some logical lines to multiple physical lines so the code does not get truncated.
for ix, it in enumerate([('\n', 2 >> 1), \
    ("larur ylurt", (8 >> 1) + 1), ('\n', 1 << 1),]):
    for tm in range(it[1]):
        print chr(ord(it[0][::-1][0]) - 2 ** 5) + \
            it[0][::-1][(1 >> 8) - (2 ** 8 - 1):] \
            if ix % 2 == 1 else it[0] * int(bin(4) \
            and bin(1), 2) * ix
If you could, how long did it take you to solve it?

I'll publish the answer in my next post, for those who could not get it.

- Enjoy.


- Vasudev Ram - Online Python training and consulting

I conduct online courses on Python programming, Unix/Linux (commands and shell scripting) and SQL programming and database design, with personal coaching sessions.

Contact me for details of course content, terms and schedule.

Get DPD: Digital Publishing for Ebooks and Downloads.

Hit the ground running with my vi quickstart tutorial. I wrote it at the request of two Windows system administrator friends who were given additional charge of some Unix systems. They later told me that it helped them to quickly start using vi to edit text files on Unix.

Check out WP Engine, powerful WordPress hosting.

Own a piece of history:
Legendary American Cookware

Teachable: feature-packed course creation platform, with unlimited video, courses and students.

Track Conversions and Monitor Click Fraud with Improvely.


Posts about: Python * DLang * xtopdf

My ActiveState Code recipes

Follow me on:


1 comment:

Vasudev Ram said...

Sorry, readers:

The initial version of this post that I published, had a few typos: I had forgotten to escape some less than and greater than characters in the code snippet. Fixed it now. Apologies to those seeing the post twice as a result, via blog aggregators.