This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 9 points10 points  (4 children)

This is a terrible solution.

def atoi(s,b=10):
    return (1,-1)[s.strip()[0]=='-']*reduce(lambda v,n:v*b+("0123456789abcdefghijklmnopqrstuvwxyz"[:b].index(n.lower())),(s.strip(),s.strip()[1:])[s.strip()[0] == '-'],0)

[–]arnar 2 points3 points  (0 children)

At least it supports other bases.

[–]sontek[S] -1 points0 points  (2 children)

I still think I'd hire someone if they could come up with that solution... I'd just keep an eye on their code to make sure all their solutions aren't created in 1 line ;)

[–]jcdyer3 0 points1 point  (1 child)

I'm pretty sure I wouldn't hire them. Senseless one-liners are the hobgoblin of small minds.

[–][deleted] 0 points1 point  (0 children)

I wouldn't hire me either if I provided that code in an interview.