[Tutor] Critique of program

Bill Burns billburns at pennswoods.net
Fri Nov 19 00:32:00 CET 2004


> Bill Burns wrote:
> >Like you mention, I might need to split this into four pieces. I'm sure I
> > will if I use a dict as many of the keys would be the same. Every type of
> > pipe has a 1/2", 3/4", 1", etc.
>
> Well, you could always key the dictionary with a tuple of (type, size).
> That should give you unique keys for each entry, right?  And if you need
> to iterate through, instead of doing random lookups, they keys() list
> should sort (and filter) nicely...

I hadn't even considered this. I was stuck in the mind set that I would need
a dict that looked like this:

pipeDict = {'1/2"': .622, '3/4"': .824, '1"': 1.049}

But doing it as you mentioned, makes perfect sense....

pipeDict = \
{('steel','1/2"'): .622, ('steel','3/4"'): .824, ('steel','1"'):1.049}

Now I can have one dict that contains all types & sizes of pipe.

Thanks for the help.

Bill


More information about the Tutor mailing list