Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found