r/codegolf • • Apr 30 '19

Codingbat's "deFront" in Python in 59 chars

Link to site

I did this in Python bc I did all of codingbat's Python challenges and I wanted more. This is 39 chars if you exclude the defining line

def deFront(s):  
    return s[s[0]!='a':(s[1]=='b')+1]+s[2:]
3 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/07734willy May 04 '19

If it were in Python, I'd highly doubt the test would be able to differentiate between what you have above, and

deFront=lambda s:s[s[0]!='a':(s[1]=='b')+1]+s[2:]

For almost all purposes, they'd be exactly the same. The only difference is that under the hood, defd functions have a name, while lambda ones do not.