python interview quuestions

Rolando Espinoza La Fuente darkrho at gmail.com
Wed Aug 11 04:27:32 CEST 2010


On Fri, Aug 6, 2010 at 10:31 PM, Tim Chase
<python.list at tim.thechases.com> wrote:
[...]
>> 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 :)

I didn't believe it could take more than 5 minutes, but this took me
~10 minutes,
though I'm familiar with python and I did the FizzBuzz one-liners before:
http://gist.github.com/518370

Well.. I tried to use generators to make it "cool" but changed it for
a test-friendly approach.
I'll find hard to remember the one-liners in an interview and get it right.

Rolando Espinoza La fuente
www.insophia.com



More information about the Python-list mailing list