print " ".join(a) That's ugly :/ . This makes sense implementation-wise1, but I still2 hate the fact that join is method of the separator rather than the group of strings you join.

[1] This let's you join work on any iterable (a string, a generator, a set...), not just a list. And the only condition for being an iterable in python is to define __iter__. Because of the duck typing3 philosophy of python, iterables are only defined by what they do (can be itered over), not what they are (member of a class, or doing a role), so there is nowhere to write code that would apply to all iterables. This means writing join somewhere else than in the object whose elements you join. Since you get a string, putting that in the string module is the obvious place, but a class method like str.join(*iterables, sep=" ") would have made more sense to me (plus you get a default separator to mirror the default of split).

[2] I used to hate the fact that you end an iteration with an exception. Because I used to see them as meaning that something bad or invalid as happened. But if you see them as meaning "not the nominal case", which is what exception means in English, it's actually an interesting way to solve the Semipredicate problem (maybe a little on the heavy side, since you have to unroll the whole try catch mecanism...).

[3] Iterables are actually one of the cases where I like duck programming. It's an iterable if you can iterate over it, period. But otherwise I prefer perl's "it's a string if I'm doing something stringy, it's a number if I'm counting on it".

I got quite philosophical on that post xD


In reply to Re: Python tricks by Eily
in thread Python tricks by pme

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.