<br>thanks for the feedback - i will go through your comments line by line adjust and test and will re-post when complete.<br><br>GTXY20<br><br><div class="gmail_quote">On Jan 4, 2008 9:29 PM, Kent Johnson <<a href="mailto:kent37@tds.net">
kent37@tds.net</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Tiger12506 wrote:<br><br>> Ouch. Usually in OOP, one never puts any user interaction into a class.
<br><br>That seems a bit strongly put to me. Generally user interaction should<br>be separated from functional classes but you might have a class to help<br>with command line interaction (e.g. the cmd module in the std lib) and
<br>GUI frameworks are usually built with classes.<br><div class="Ih2E3d"><br><br>>> uh, tf = line.split(',')<br>>> if uh in self.uhdata:<br>>> f=
self.uhdata[uh]<br>>> if tf not in f:<br>>> f.append(tf)<br>>> else:<br>>> self.uhdata[uh]=[tf]<br>><br></div>> This can read
<br>><br>> try:<br>> f = self.uhdata[uh]<br>> except KeyError:<br>> self.uhdata[uh] = []<br>> finally:<br>> self.uhdata[uh].append(tf)<br><br>These are not equivalent - the original code avoids duplicates in
<br>self.uhdata[uh].<br><br>Possibly self.uhdata[uh] could be a set instead of a list. Then this<br>could be written very nicely using defaultdict:<br><br>from collections import defaultdict<br> ...<br> self.uhdata = defaultdict(set)
<br> ...<br> self.uhdata[uh].add(tf)<br><div class="Ih2E3d"><br>>> for uh, Sections in self.uhdata.items():<br>>> Sections.sort()<br>><br></div>> This will not work. In the documentation, it says that dictionary object
<br>> return a *copy* of the (key,value) pairs.<br>> You are sorting those *copies*.<br><br>No, the original code is fine. The docs say that dict.items() returns "a<br>copy of a's list of (key, value) pairs". This is a little misleading,
<br>perhaps. A dict does not actually contain a list of key, value pairs, it<br>is implemented with a hash table. dict.items() returns a new list<br>containing the key, value pairs.<br><br>But the keys and values in the new list are references to the same keys
<br>and values in the dict. So mutating the values in the returned list, via<br>sort(), will also mutate the values in the dict.<br><div class="Ih2E3d"><br><br>>> missingpgcounts={}<br>>> fmissingpgcounts=[]
<br>>> for x in self.uhdata:<br>>> for f in self.uhdata[x]:<br>>> if f not in fmissingpgcounts:<br>>> fmissingpgcounts.append(f)<br>
><br></div>> fmissingpgcounts = [f for f in self.uhdata.itervalues() if f not in<br>> fmissingpgcounts]<br>> Ahhh... This looks like a set.<br>> fmissingpgcounts = set(self.uhdata.itervalues())<br><br>Again, this is not quite the same thing. The original code builds a set
<br>of the contents of the values. You are building a set from the values<br>(which are already lists). You still need one loop:<br>fmissingpgcounts = set()<br>for v in self.uhdate.itervalues():<br> fmissingpgcounts.update
(v)<br><br>> self.pgcounts = dict((x,0) for x in fmissingpgcounts)<br><br>or, self.pgcounts = dict.fromkeys(fmissingpgcounts, 0)<br><br>That's all I have energy for...<br><font color="#888888">Kent<br><br></font></blockquote>
</div><br>