4 ms·
-> 'If the implementation is easy to explain, it's a good idea.' - Well, the zen says that it may be a good idea, but i considered it. It gave e a wrong answer.
by Vaskivo 13y ago
-> 'If the implementation is easy to explain, it's a good idea.' - Well, the zen says that it may be a good idea, but i considered it. It gave e a wrong answer.
-> 'squares = [i2 for i in xrange(10000)]'
&
'squares = (i2 for i in xrange(10000))'
- Although they are similar, they are not the same, as one returns a list and the other a generator. I can index, pop, insert, etc in the list but can't in the generator.
(I cheated on the 5th one. I wasn't sure what (2) * 3 would return. My hunch was correct though)
- '(2 or 3) * (5 and 7)' - I don't feel this is very pythonic. It's a language trick, and python code shouldn't rely on that.
Got 4/6, failed the 1st and messed up the 5th.
I don't think it's a very good test. To chck for 'pythonism' you should probably try to see if the applicant knows what the zen means. You should also chack for intermediate/advanced features. List/dict comprehensions and generator expressions. The data structures, their characteristics and pitfalls. Properties, magic methods, etc.
I mean, method lookup order in multiple inheritance. Multiple inheritance is usually a big 'no-no', so I don't feel that it is a worthy question.
I also couldn't see who this test was for. For begginers, pros? What do you want to see? If they know python? If it's an experienced programmer, he may not know python, but can master it fast.
Just my 5 cents...
[EDIT] Submitted too early