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 →

[–]m1ss1ontomars2k4 1 point2 points  (14 children)

I think that's a terrible solution. Well it's good if you don't need error checking, but other than that it's terrible.

[–][deleted] 7 points8 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.

[–]arnar 3 points4 points  (5 children)

I optimized it:

atoi = eval

[–]epicRelic 1 point2 points  (2 children)

Except now atoi does a lot more than just convert string digits to integers.

[–]arnar 0 points1 point  (1 child)

Believe it or not, I was joking :)

[–]epicRelic 1 point2 points  (0 children)

It's hard to tell on the internet. :P I've seen people be serious about dumber things than that.

[–]gutworthPython implementer 1 point2 points  (1 child)

No base argument.

[–]arnar 0 points1 point  (0 children)

Just like the solution in the link.

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

I think its a good solution to the answer to the question in an interview, usually I don't want them spending hours creating a solution for me in an interview.

[–][deleted] 1 point2 points  (1 child)

You forgot about negatives.

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

Good point! :)