Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Eric Abrahamsen
On Mar 4, 2008, at 11:04 AM, Kent Johnson wrote: > Eric Abrahamsen wrote: >> Itertools.groupby is totally impenetrable to me > > Maybe this will help: > http://personalpages.tds.net/~kent37/blog/arch_m1_2005_12.html#e69 > > Kent > It did! Thanks very much. I think I understand now what's going o

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Kent Johnson
Eric Abrahamsen wrote: > Itertools.groupby is totally impenetrable to me Maybe this will help: http://personalpages.tds.net/~kent37/blog/arch_m1_2005_12.html#e69 Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Eric Abrahamsen
Well I expected to learn a thing or two, but I didn't expect not to understand the suggestions at all! :) Thanks to everyone who responded, and sorry for the typo (it was meant to be object_id throughout, not content_type). So far Michael's solution works and is most comprehensible to me – i

Re: [Tutor] Python and displaying mathematical equations?

2008-03-03 Thread John Fouhy
On 04/03/2008, Shuai Jiang (Runiteking1) <[EMAIL PROTECTED]> wrote: > Hello, I'm trying to create an application that retrieves and displays > (probably in HTML or PDF format) math problems from a database. > The problem is that I need some sort of mechanism to display mathematical > equations. If

[Tutor] Python and displaying mathematical equations?

2008-03-03 Thread Shuai Jiang (Runiteking1)
Hello, I'm trying to create an application that retrieves and displays (probably in HTML or PDF format) math problems from a database. The problem is that I need some sort of mechanism to display mathematical equations. I'm trying to not use Latex as it would cause the users to install Latex (and

Re: [Tutor] [tutor] Finding image statistics

2008-03-03 Thread Kent Johnson
Varsha Purohit wrote: > Yeahh so by doing this i am counting only the difference part since we > have grayscaled the image and assuming it will count only the pixels > that evolve as difference Yes > if i use sum2 instead of sum i think it > will give squared sum which is area... and if

Re: [Tutor] [tutor] Finding image statistics

2008-03-03 Thread Varsha Purohit
Yeahh so by doing this i am counting only the difference part since we have grayscaled the image and assuming it will count only the pixels that evolve as difference if i use sum2 instead of sum i think it will give squared sum which is area... and if i just use count it would count the number

[Tutor] sorting objects on two attributes

2008-03-03 Thread Michael H. Goldwasser
Hello Eric, Your basic outlook is fine, but you can do it much more efficiently with a single sort. Here's the way I'd approach the task (untested): # -- # first compute the latest date for each id group; uses O(n) time newest = {} f

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Kent Johnson
Chris Fuller wrote: > You could have a hierarchical sort > function: > > def hiersort(a,b): >if a.attr1 != b.attr1: > return cmp(a.attr1, b.attr1) >else: > if a.attr2 != b.attr2: > return cmp(a.attr2, b.attr2) > else: > return cmp(a.attr3, b.att3) > >

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Chris Fuller
Almost. And better than my original idea. You could have a hierarchical sort function: def hiersort(a,b): if a.attr1 != b.attr1: return cmp(a.attr1, b.attr1) else: if a.attr2 != b.attr2: return cmp(a.attr2, b.attr2) else: return cmp(a.attr3, b.att3) l

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Kent Johnson
Andreas Kostyrka wrote: > l.sort(key=lambda x: (x.content_type, x.submit_date)) > > Now, you can construct a sorted list "t": > > t = [] > for key, item_iterator in itertools.groupby(l, key=lambda x: (x.content_type, > x.submit_date)): > sorted_part = sorted(item_iterator, key=lambda x: x.s

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Kent Johnson
Eric Abrahamsen wrote: > I have a list of objects, each of which has two attributes, object_id > and submit_date. What I want is to sort them by content_type, then by > submit_date within content_type, and then sort each content_type block > according to which block has the newest object by

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Andreas Kostyrka
Well, this assumes that all named attributes do exist. If not, you need to replace x.attr with getattr(x, "attr", defaultvalue) ;) l.sort(key=lambda x: (x.content_type, x.submit_date)) Now, you can construct a sorted list "t": t = [] for key, item_iterator in itertools.groupby(l, key=lambda x:

[Tutor] sorting objects on two attributes

2008-03-03 Thread Eric Abrahamsen
I have a grisly little sorting problem to which I've hacked together a solution, but I'm hoping someone here might have a better suggestion. I have a list of objects, each of which has two attributes, object_id and submit_date. What I want is to sort them by content_type, then by submit_date

Re: [Tutor] Need help with encoder & decryption keys

2008-03-03 Thread Andreas Kostyrka
Well, actually, ssh can also protect private keys with a cryptographic pass phrase. But this is often not what is wanted as it implies that the user needs to provide the pass phrase every time it is used. (Well, that's not the complete truth, man ssh-agent, but that's completely different thing

Re: [Tutor] Need help with encoder & decryption keys

2008-03-03 Thread Andreas Kostyrka
And if it's a string constant, in many cases running strings (Unix program) on the pyc file will reveal it too. All this basically turns down to the problem, that it's hard to embed an encryption key in a program, so that it's not possible to extract it. Notice the the current crop of HDDVD/Blu