Trees

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jan 21 09:47:56 EST 2015


Rustom Mody wrote:

> On Wednesday, January 21, 2015 at 1:27:39 PM UTC+5:30, Stephen Hansen
> wrote:
[...]
> Among my teachers of CS, there were two – both brilliant — one taught me
> Numerical Analysis, the other taught me programming.

I wonder just how brilliant the Numerical Analysis guy really was.


> The point is that the two of them disagreed strongly on what programming
> was about.
> 
> The numerical analyst could see no earthly reason to use anything other
> than Fortran.

Would you consider a cook who boiled everything "brilliant"? Somebody who
insisted that there was no earthly reason to have an oven, a frying pan, a
wok, or a steamer?

Or somebody who insisted that the *one and only* use for chemistry was to
set fire to wood and boil water?

Computers are used for vastly more than just numerical analysis.


> The programmer had horror stories to tell about how Fortran damages the
> brain: eg programs that inherently need a while-loop (eg binary search)
> seem to be
> distinctly out of the reach of the Fortran programmer.  Recursion...
> And much else.
> 
> The numerical analyst of course had no use for this philosophizing.

And how did this brilliant numerical analyst perform fast, efficient
searches of sorted data?


> The view that strings and floats are more fundamental than containers and
> maps reminds me of this view.

A strange comment to make.

I can insert a string or a float inside a container or map, but I cannot
insert a container or map inside a string or float.

Consider the computer hardware we use. Certain data structures are
fundamental to the architecture we use: bytes, pointers, ints, arrays are
very low-level. Floats are a little more complex -- they have a more
complex internal structure than ints. Hash tables are more complex still.

 
> For me python is neat because I can write: [1,2,3]
> when I want a list.

> But it does not go nearly far enough.
> 
> I would like a set to be {1,2,3} or at worst ⦃1,2,3⦄
> and a bag to be ⟅1,2,3⟆

In Python, you can write sets {1, 2, 3}.

Out of curiosity, what input method did you use to get those Unicode
characters? How many keystrokes or mouse clicks did it take to get this?

\N{LEFT S-SHAPED BAG DELIMITER} 1, 2, 3 \N{RIGHT S-SHAPED BAG DELIMITER}


"bag([1, 2, 3])" requires only 16 keypresses, and it is visible on virtually
every computer, while ⟅ ⟆ look like small boxes to me and probably most
people.

[...]
> More irksome that for the second we've to preface with
> 
> from collections import Counter
> 
> And still more a PITA that a straightforward standard name like bag (or
> multiset) is called by such an ungoogleable misleading name as counter.

It is not misleading. collections.Counter is a class for counting (i.e. a
counter), not a bag. It is merely *similar* to a bag, but the API is not
the same as the usual bag API because the motivating design is not the same
as for bags.

As for being "ungoogleable", that is just simply false. Perhaps you forgot
to push the enter key after typing in your search terms?

https://www.google.com.au/search?q=python+counter

The top three links are:

https://docs.python.org/2/library/collections.html‎
https://docs.python.org/3.3/library/collections.html‎
http://pymotw.com/2/collections/counter.html

and seven out of the ten links on the first page of results are about
Counter.

Your results may differ from mine, since Google bubbles your searches. But
Duck Duck Go doesn't:

https://duckduckgo.com/?q=python%20counter

Its results are not quite as good as Google's, but it finds the backported
Counter class on PyPI (which Google didn't) and it too links to the Python
Module Of The Week page. Adding "collections" to the search terms brings
the results up to Google quality.

So as you can see, it simply is not true that "Counter" is ungoogleable.



-- 
Steven




More information about the Python-list mailing list