Stupid ways to spell simple code

Russel Walker russ.pobox at gmail.com
Tue Jul 2 03:33:01 EDT 2013


On Sunday, June 30, 2013 8:06:35 AM UTC+2, Chris Angelico wrote:
> There's a bit of a discussion on python-ideas that includes a function
> 
> that raises StopIteration. It inspired me to do something stupid, just
> 
> to see how easily I could do it...
> 
> 
> 
> On Sun, Jun 30, 2013 at 3:45 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 
> Re: [Python-ideas] "Iteration stopping" syntax
> 
> >>>> def stop():
> 
> > ...     raise StopIteration
> 
> 
> 
> Here's a much more insane way to spell that:
> 
> 
> 
> stop = (lambda: 0 and (yield 1))().__next__
> 
> 
> 
> 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!
> 
> 
> 
> ChrisA

Here's a way to count items in a string.

def count(string, x):
    return len(''.join(string)) - len(''.join(string).replace(x, '')) / len(x)



More information about the Python-list mailing list