I suppose most Pythonistas would rather prefer making rtoa a class variable and using roman_to_dec as a method. TIMTOWTDI. ;-)
Ha ha! Yes, despite the Zen of Python aiming for "There should be one -- and preferably only one—obvious way to do it" I could not help but notice when playing code golf in multiple languages that Python sometimes out-TMTOWTDI-ed them all! Also, without TMTOWTDI code golf is no fun at all and, surprisingly, code golf is way more popular in Python than Perl nowadays.

The TMTOWTDI examples below were taken from:

Consider how to create a "Dear John" string in each of the four languages:

"Dear $name" # Perl and PHP "Dear %s" % expr # Python and Ruby % printf-like operator "Dear {0}".format(expr) # Python format string method "Dear "+`expr` # Python backticks (TMTOWTDI) "Dear #{expr}" # Ruby string interpolation "Dear @{[expr]}" # Perl "Baby Cart" string interpolation

Curiously, Python is the only member of the gang of four languages to allow you to reverse the order of the two string multiply operands:

5 * "X" also produces "XXXXX" in Python! TMTOWTDI! :) 5 * "X" ... but not in Ruby (won't compile: type error) 5 x "X" ... or Perl (produces empty string)
That is, the string multiply operator is commutative in Python, but not in Perl or Ruby. This language idiosyncrasy makes string multiply based solutions most attractive in Python. To illustrate, note these code snippets from my string multiply based solutions to this game:
$"x(318%$_/9) Perl " "*(318%i/9) Ruby 318%i/9*" " Python
This is a very rare example of Python out-golfing both Perl and Ruby.

From my early 195-stroke function-based Python solution:

n=99 z=lambda:`n or 99`+" bottle"+"s of beer on the wall"[n==1:] while n:y=z();n-=1;print"%s, %s.\n"*2%(y,y[:-12],n and"Take one down a +nd pass it around"or"Go to the store and buy some more",z())
notice the expression:
n and"Take one down and pass it around"or"Go to the store and buy some + more"
Shortening the two strings above to "Take" and "Go to" for clarity, let's consider the many and varied ways of doing this in Python (TMTOWTDI):
"Take"if n else"Go to" (n>0)*"Take"or"Go to" ["Go to","Take"][n>0] ("Go to","Take")[n>0] n and"Take"or"Go to" "GToa kteo"[n>0::2] # "Slice and Dice" wins this golf!
As you can see, I missed the winning Python "Slice and Dice" tactical trick in this game.


In reply to Re^7: A short whishlist of Perl5 improvements leaping to Perl7 (Python TMTOWTDI) by eyepopslikeamosquito
in thread A short whishlist of Perl5 improvements leaping to Perl7 by rsFalse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.