No 1.6! (was Re: A REALLY COOL PYTHON FEATURE:)
Martijn Faassen
m.faassen at vet.uu.nl
Thu May 18 07:43:13 EDT 2000
François Pinard <pinard at iro.umontreal.ca> wrote:
> "Magnus Lie Hetland" <mlh at idi.ntnu.no> writes:
>> This is indeed a bit strange IMO... If I were to join the elements of a
>> list I would rather ask the list to do it than some string... I.e.
>> ['foo', 'bar', 'baz'].join(', ')
I agree that doing ' '.join(['foo', 'bar', 'baz'] is odd. I'd also agree
that the list syntax looks more readable, though it's more special case.
The core of the problem may be that we simply don't feel that we're
doing a join() on the join character. In daily life we we say:
I sit on the chair
In Python this would be:
chair.sit()
Similarly:
I append to the list
list.append()
I.e. the method is the verb, and the noun is the object.
If we have arguments, it works like this:
I quickly sit on the chair
chair.sit(speed='quickly')
I append foo to the list
list.append('foo')
I draw on a paper with a blue color
paper.draw(color='blue')
In the case of 'foo'.join() this stops making sense:
I join the list of strings with spaces.
' '.join(list)
In this case, it feels obvious to us that the *list* is the big target,
and the space is what we're joining with. We don't think:
I join the join character with a list.
Of course there are ways to rewrite it so it makes more sense. Just like:
I draw with a blue pen
can be expressed thusly:
pen = Pen(color="blue")
pen.draw()
You can say something like:
I do the joining with the space join character.
join_char = " "
join_char.join()
But here I omit the list. Once the list comes into the picture, the
list *still* feels like the most important thing. So the pen example and
the join character example are not exactly equivalent.
lots-of-instinctive-language-analysis-ly yours,
Martijn
--
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?
More information about the Python-list
mailing list