Entry 3129

weird fuction

   

Submitted by anonymous on Feb. 2, 2010 at 8:50 p.m.
Language: Python. Code size: 429 bytes.

#/usr/bin/env python

import re

class BadInput(Exception): pass

def weird(data):
    prefix, suffix = "WEIRD_PREFIX_", "_WEIRD_SUFFIX" 
    words = "BEGIN", "GENERATE", "END"
    words = map(lambda w: prefix + w + suffix, words)
    exp = "(" + "|".join(words) + ")"
    try:
        return words.index(re.match(exp, data).group())
    except AttributeError, ValueError:
        raise BadInput("Bad data", data)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).