[Tutor] Re: Sorting/filtering data, dictionary question
Bill Burns
billburns at pennswoods.net
Tue Jan 4 03:26:26 CET 2005
On Monday 03 January 2005 8:35 am, Bob Gibson wrote:
> Bill:
>
> Could you have the "LineEdit#" be your sortable field? If each # after
> the "LineEdit" prefix were the same length, then you could easily sort on
> it.
Bob,
Using your suggestion, I did a little test on a modified version of my pipe
dictionary:
pipeDict = \
{('lineEdit001','Steel(Std)','1/2"',.85): .622,
('lineEdit002','Steel(Std)','3/4"',1.13): .824,
('lineEdit003','Steel(Std)','1"',1.678): 1.049,
('lineEdit004','Steel(Std)','1-1/4"',2.272): 1.38,
('lineEdit005','Steel(Std)','1-1/2"',2.717): 1.61,
('lineEdit006','Steel(Std)','2"',3.652): 2.067,
('lineEdit007','Steel(Std)','2-1/2"',5.79): 2.469,
('lineEdit008','Steel(Std)','3"',7.57): 3.068,
('lineEdit009','Steel(Std)','3-1/2"',9.11): 3.548,
('lineEdit010','Steel(Std)','4"',10.79): 4.026,
('lineEdit011','Steel(Std)','5"',14.62): 5.047,
('lineEdit012','Steel(Std)','6"',18.97): 6.065,
('lineEdit013','Steel(Std)','8"',28.55): 7.981,
('lineEdit014','Steel(Std)','10"',40.48): 10.02}
And using these functions again (slightly modified):
def someReport():
report = []
for name, typ, size, weight in pipeDict:
report.append((name,typ,size,weight))
report.sort()
newReport = filterPipeData(report)
print newReport
def filterPipeData(data):
"""idea for list comp, from Kent"
return [(typ,size,weight) for name, typ, size, weight in data]
It works perfectly! Thank You! Notice how I removed the other "size" number
that was in the previous dict.
You mentioned that the #'s I use, will have to be the same length. My GUI uses
100 lineEdits, so a numbering scheme like 001 - 100 should sort correctly (I
guess). I haven't tried it on the whole dictionary yet, but I will! Changing
the numbering of the lineEdits, is *not* a problem at all.
Thanks again,
Bill
More information about the Tutor
mailing list