Wednesday, 29 August 2007

Python is neat

You know that nice feeling, when your language lets you transform your task into one line of code while still being readable? I needed to strip the quoted substrings from input string. The task was pretty easy, since there was no escaping, or nesting quotes. And I know, I can see it's more than one line: it requires a little bit of imagination :).


def removeQuotedSubstrings(origString):
return ''.join(x for num, x in
enumerate(origString.split('"')) if num % 2 == 0)

No comments: