A ListComp that maintains its own state (Was: Re: turing machine in an LC)

Michael Spencer mahs at telcopartners.com
Tue Feb 8 22:42:29 EST 2005


Carl Banks wrote:
> 
> Pay attention, chief.  I suggested this days ago to remove duplicates
> from a list.
> 
> from itertools import *
> [ x for (x,s) in izip(iterable,repeat(set()))
>   if (x not in s,s.add(x))[0] ]
> 
> ;)
Sorry,  I gave up on that thread after the first 10 Million* posts.  Who knows 
what other pearls I may have missed?

Anyway, the good news is that you appear to have identified a new design 
pattern, and will soon become very famous:

According to:
http://www.cmcrossroads.com/bradapp/docs/patterns-nutshell.html#Patterns_What

A "pattern" is ...

     * An abstraction from a concrete form which keeps recurring in specific, 
non-arbitrary contexts. [twice in one week]

     * A recurring solution to a common problem [perl-python spam] in a given 
context and system of forces.

     * A named "nugget" of instructive insight, conveying the essence of a 
proven solution to a recurring problem in a given context amidst competing 
concerns. [who could doubt it?]

     * A successfully recurring "best practice" that has proven itself in the 
"trenches". [of this list anyway]

     * A literary format for capturing the wisdom and experience of expert 
designers, and communicating it to novices [I think we're 5 for 5]


So, I would get the book out without further delay, before some other 
Johnny-come-lately lays claim.

BTW, Do you have a 1-line-LC-wiki yet?

Michael


* with due respect to Marvin





More information about the Python-list mailing list