The Artima Developer Community
Sponsored Link

Python Buzz Forum
crazy snake

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
maxim khesin

Posts: 251
Nickname: xamdam
Registered: Mar, 2005

Maxim Khesin is developer for Liquidnet. I like C++, python, attend design patterns study group/NYC.
crazy snake Posted: Mar 12, 2005 12:15 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by maxim khesin.
Original Post: crazy snake
Feed Title: python and the web
Feed URL: http://feeds.feedburner.com/PythonAndTheWeb
Feed Description: blog dedicated to python and the networks we live in
Latest Python Buzz Posts
Latest Python Buzz Posts by maxim khesin
Latest Posts From python and the web

Advertisement

I recently send around a bug I found (in my own code!) to some of my collegues as a puzzle and hid the answer in the end in the following obfuscated python bit:
" You will get the answer when you execute this from command-line:

python -c "import new, sys;print (lambda s: s and s[-1]+new.function(sys._getframe().f_code, globals())(s[:-1]) or s)('.srotarepo noisrevnoc fo eraweB :nosseL \n.tcejbo TNOFH gniylrednu eht llik lliw rotcurtsed s\'tnoFC lanigiro eht dna ,ton si tI \n.tcerroc yllacitnames si tnemngissa tnoFC taht kniht uoy sekam rotcurtsnoc gnitpecca-TNOFH eht htiw noitanibmoc ni rotarepo noisrevnoc TNOFH\n')"

The only really cool (and hopefully useless :) thing here is the list/string reverse function written as a recursive lambda. Of course there is no normal way to call a lambda in python recursively since it doesn't have a name, so you have to poke around the current frame object to get what you want. So you get this beauty:

(lambda s: s and s[-1]+new.function(sys._getframe().f_code, globals())(s[:-1]) or s)

I think I'll go take a shower now :)

Read: crazy snake

Topic: Latin Python Previous Topic   Next Topic Topic: The Unbearable Importance Of Detail

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use