Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.python Subject: Re: Stupid ways to spell simple code Date: 1 Jul 2013 12:59:16 GMT Organization: Norwich University Lines: 24 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net AqgVaw3UN3kAu2P7CamwCwhSrkCHIKP3aYZlnqkWvN79nPO5e7 Cancel-Lock: sha1:pnr3NMSYnYFm4X8ExRiOeW9SA6w= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: csiph.com comp.lang.python:49557 On 2013-06-30, Chris Angelico wrote: > So, here's a challenge: Come up with something really simple, > and write an insanely complicated - yet perfectly valid - way > to achieve the same thing. Bonus points for horribly abusing > Python's clean syntax in the process. > > Go on, do your worst! I've often thought it was redundant for Python to support 'if' when it has dictionaries, cf the rationale for having no 'switch'. valid_name = None while not valid_name: name = input("Enter your name: ") valid_name = { True: lambda: print("No name longer than 20 letters."), False: lambda: True, }[len(name) > 20]() Much better. -- Neil Cerutti