Q: What does "Sparse is better than dense" mean? (Python Zen)
Mike C. Fletcher
mcfletch at rogers.com
Thu Jul 11 16:23:59 EDT 2002
Hmm, strangely, I'd always thought the "sparse is better than dense"
line was refering to ideas of sparse versus dense data structures and/or
programs. For instance, if we have an 11-item sequence where we want to
record which items are "important", we see two possibilities:
filterSet = [0,0,0,1,0,0,0,0,1,0,0,0]
and
filterSet = {3:1, 8:1}
and would choose the "sparse" matrix (the dict) instead of the "dense" one.
In a more general sense, record what is important explicitly, and where
it is relevant, while not recording that which is unimportant to the
matter at hand.
Or even more generally, make your intentions clear by coding just what
you mean, not everything that could possibly be. See the use of
exceptions, which encourage you to code the "positive image" in a
particular function, and allow a higher-level of code to deal with the
outlier cases (the 0's in the array, which we don't really have anything
to say about).
But, of course, I'm notoriously bad at channeling Tim, so the whitespace
thing is probably it :) ,
Mike
> Miki Tebeka <tebeka at cs.bgu.ac.il> wrote:
>
>>Although it's in the Humor section I take the Python Zen
>>(http://www.python.org/doc/Humor.html#zen) quite seriously.
>>However I can understand what does “Sparse is better than
>>dense” means.
...
More information about the Python-list
mailing list