[Tutor] Setting thresholds in a compact way

Alan Gauld alan.gauld at yahoo.co.uk
Thu Jan 2 05:16:10 EST 2020


On 02/01/2020 03:25, Martin A. Brown wrote:

> I don't know how to apply the sparse array solution, suggested by Alan.

Sparse arrays are a bit of a faff and only worthwhile in the specific
scenario where there are a lot of choices, so an if/elif ladder would be
cumbersome - I'm thinking at least double digit lengths...20 or 30 say.
They are also effective where you have a broad range of possible test
values but only a relatively few sub-ranges which require action.

It was purely a response to Bob's question about how to handle the
long ladder case. Not a general recommendation.
Certainly not for this particular problem.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list