Dear Alan and tutors, I apologize for careless description of my problem that lead to confusion. the problem arises due to large range of numbers and range has direction (both ascending and descending).
I am giving an example from my real problem. What I want to do: I want to check if a[.][1] and a[.][2] are 'within the range' of any element of b[.][1] or b[.][2]. (here '.' means any sub-element of list b. a[.][1] and a[.][2] or b[.][1] b[.][2] can be either ascending or descending order Ascending example from list a and b: 'xa','1511255', '1511279' 'xb','7516599','7516623' 'G1','1511200','1511325' 'G2','7516500','7516625' descending order from list a and b: 'xc','98356290','98356266' 'G3','98356335','98356126' a = [['xa','1511255', '1511279'],['xb','7516599','7516623'],['xc','98356290','98356266']] b = [['G1','1511200','1511325'],['G2','7516500','7516625'],['G3','98356335','98356126']] >>> for item1 in a: ... i1st = int(item1[1]) ... i1en = int(item1[2]) ... for item2 in b: ... i21 = int(item2[1]) ... i22 = int(item2[2]) ... if i1st and i1en in xrange(i21,i22): ... print "\t".join(item1)+'\t'+"\t".join(item2) ... if i1st and i1en in xrange(i22,i21): ... print "\t".join(item1)+'\t'+"\t".join(item2) ... xa 1511255 1511279 G1 1511200 1511325 xb 7516599 7516623 G2 7516500 7516625 xc 98356290 98356266 G3 98356335 98356126 Issue 1: a. Range of numbers is too high and xrange is also too slow. I used xrange instead of range - a slow process Issue 2: Is this is a correct way to tackle this kind of problem. Issue 3: I have 200K elements in a anb b lists. this code has been running for last 18 hours and only 800 elements of 200K have been evaluated. Could tutors help me with 3 issues. Thank you. srini --- On Tue, 10/21/08, Alan Gauld <[EMAIL PROTECTED]> wrote: > From: Alan Gauld <[EMAIL PROTECTED]> > Subject: Re: [Tutor] finding numbers in range of of numbers > To: tutor@python.org > Date: Tuesday, October 21, 2008, 5:10 AM > "Srinivas Iyyer" <[EMAIL PROTECTED]> > wrote > > > [[10,45],[14,23],[39,73],[92,135]] > > > > I want to identify if any of the items in this list > are in range of > > [5,100] > > Sorry, I have no idea what you mean by that. Can you give > an example of passing and failing tests? > > For example do any/all of the elements in your sample > list pass the test? If so why? > > Often if you think carefullly and specifically about your > requirement the solution will become apparent. And if > you don't you are open to ambiguity and confusion. > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor