Skip to content


Spaceballs: The Python Script

“Before you die, there is something you should know about us, Lone-Star…”

def unfoldFilter(unfoldFunction, filterFunction, iterable):
    for item in iterable:           
        for result in unfoldFunction(item):            
            if filterFunction is None or apply(filterFunction, [result]):
                yield result

assert darkHelmet in unfoldFilter(lambda p: p.roommates, lambda p: p.isFormer(), 
    unfoldFilter(lambda p: p.children, None, 
        unfoldFilter(lambda p: p.siblings, None, 
            unfoldFilter(lambda p: p.parents, None, 
                unfoldFilter(lambda p: p.children, lambda p: p.isMale(), 
                    unfoldFilter(lambda p: p.siblings, None, 
                        unfoldFilter(lambda p: p.siblings, lambda p: p.isMale(), 
                            unfoldFilter(lambda p: p.parents, lambda p: p.isMale(), list(loneStar))
                        )
                    )
                )
            )
        )
    )

assert makesThem(darkHelmet, loneStar) is None

For those who don’t get the joke, the movie “Spaceballs” self-parodied itself with a series of whimsical merchandising options and contained a gag referencing Star Wars’ iconic “I am your father”, except… well, a little more complex.

Posted in Programming.

Tagged with .