Hacker News new | past | comments | ask | show | jobs | submit login

See the design FAQ here: http://docs.python.org/faq/design.html#why-is-join-a-string-...

Admittedly, the join syntax is somewhat counter-intuitive and arguably ugly, but it does the job without defining new built-in functions or adding extra syntax. If you really can't stand the syntax, you can always do this:

    # old style way of joining strings
    import string
    string.join([1,2,3], ' ')
or:

    str.join(' ', [1,2,3])
Of course method #1 requires importing an extra module (which can be a bit of a pain) and method #2 requires knowing more about python's implementation of str (as you argued about using str.capitalize), but they work. Generally though, the syntax isn't that bad, but you have alternatives if you want them.



$ipython

In [1]: x = [1,2,3]

In [2]: y = [4,5,6]

In [3]: x + y

Out[3]: [1, 2, 3, 4, 5, 6]

Why use 6 [join()] characters when you can use 1 :)


Polymorphism.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: