Python Ternary

Categories: blog



I joined an exercise question posted in ITtutor’s Forum a few days back. I’ve posted PHP, ActionScript (with a little frame action, lol), Processing (custom java-based language), and 2 Python Snippet (both valid ternary emulation but latter is more feasible for use than former).

I though about it when I was waiting for the damn bus. I was on my way to buy a new keyboard, the other pc uses USB, which gives me a slight problem when setting up linux metadistro Gentoo. Yes, I’m a gentoo newbie. :|

So anyway the bus took almost 2 hours of my time. Nearly driving me nuts (steering wheel in the crotch, one of bash quote). I took out my Python Pocket Reference (yes, I bring something to read just in case something like this would happen). And read page by page, list comprehension expressions gave me something work with. But still it cant solve the fizz buzz exercise.

I took my time googling for Python Ternary and found a nice site and in its comments there’s another nice link to Mark Pilgrim’s site.

Well.. thats about solve it. :D

Fizzle to the wizzle

for x in range(1, 101): print (x % 3 == 0 and x % 5 == 0) and ‘FizzBuzz’ or ((x % 3 == 0) and ‘Fizz’ or ((x % 5 == 0) and ‘Buzz’ or str(x)))

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.