One Liners
Posted by mkhairul - August 20, 2007 at 01:08:29 am -Categories: blog
After all this time
I thought I must simplify things. Break things line by line, make it readable for the novice. Avoiding 1-liners altogether. But now, I see that its crucial. Makes sense though. Oh well, you heard the man, bring on the 1-liners!
Some Examples
Some exercises for FizzBuzz.
for x in range(1, 101): print [[[str(x), 'Buzz'][x % 5 == 0], ‘Fizz’][x % 3 == 0], ‘FizzBuzz’][x % 5 == 0 and x % 3 == 0]
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)))
You can even download youtube videos with a Perl 1-liner. (Apart from installing all the modules).
In the end..
be careful with one liners. Comments are crucial. More than once I looked back at my code and wondering what the hell I’m writing. Should have spent more time writing the comment that made sense in a quick glance.
Now I must get back to work.
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.
