map is useless!

rantingrick rantingrick at gmail.com
Sun Jun 6 17:01:37 EDT 2010


On Jun 6, 2:48 pm, Richard Thomas <chards... at gmail.com> wrote:
> Python's map has the useful feature that nobody is in any doubt about
> what it does. I don't know much about Ruby I have to say but looking
> at that piece of syntax you gave I had no idea how to interpret it.
> Anyway, I looked it up.

Well Ruby likes to pass block in the form { ...expression... }. I
don't really care for the braces but the map is more natural in Ruby

>>> array = [1,2,3].map{|x| x.to_s}
>>> array
['1', '2', '3']
>>> array.length
3
>>> 'abc'.map{|x| x.upcase}.join
'ABC'

#-- as in python you do the nested thing --#

>>> lst = map(str, [1,2,3])
>>> lst
['1', '2', '3']
>>> len(lst)
3
>>> ''.join(map(string.upper, 'abc'))
'ABC'

Thats the only thing that bother me about Python. But in Ruby the
sky's the limit since you pass a block. And no need for that clunky
lambda.

I think Guido and Matz need to set down for a cup of joe fire up their
interpretors and exchange thoughts about language design. Some awesome
synergy could come of it and maybe even create the next best
language.

Guido can teach Matz about the importance of forced indention over
braces, docstrings, command line help, explicitly calling functions/
method, perfect keyword naming, __specialmethodnames__, the Python
Zen! And Matz can show Guido how to build a better lambda and map
functions and more syntactically correct OOP style.

Just ideas folks ;)



More information about the Python-list mailing list