python interview quuestions

Tim Chase python.list at tim.thechases.com
Fri Aug 6 22:31:30 EDT 2010


On 08/06/10 15:37, James Mills wrote:
> On Sat, Aug 7, 2010 at 6:28 AM, geremy condra<debatem1 at gmail.com>  wrote:
>> If I had to wait 5 minutes while a candidate tried to solve this
>> problem I would not hire them.
>
> Yes you do raise a valid point. It should really only take
> you a mere few seconds or so to write a solution to this.
>
> More over, it can be done in just a single line of Python.
>
> 7 if you're not very familiar with Python.

While it *can* be done in one line, I'm not sure it's the most 
legible solution.  Though I must say I like this one-line python 
version:

for i in range(1, 101): print ((i%3==0 and 'fizz' or '') + 
(i%5==0 and 'buzz' or '')) or i

(adjust "3" and "5" for your local flavor of fizzbuzz)

I'm not sure I'd hire a candidate that proposed this as a 
solution in earnest, but I'd have fun chatting with them :)

-tkc





More information about the Python-list mailing list