[Tutor] Selecting from list

Alan Gauld alan.gauld at btinternet.com
Fri Jul 19 01:00:28 CEST 2013


On 18/07/13 18:27, Hs Hs wrote:
> hi list:

Hi, please don't use an old thread to start a new one.
This message appeared under a thread dated back in January. I nearly 
gave up looking for the unread message that my reader said was there.
Start a new thread - you'll get better responses if you do.

> In the following list, is there a simply way to find element less than
> 200 sandwiched between two numbers greater than 1000.
>
> a = [3389, 178, 2674, 2586, 13731, 3189, 785, 1038, 25956, 33551]

You example is ambiguous.

What should happen in this example:

a = [3389, 178, 66, 2674, 2586, 13731, 3189, 785, 1038, 25956, 33551]

Should it list 178 and 66, one of them(which?) or neither?

Or what about:

a = [389, 178, 2674, 2586, 13731, 3189, 785, 1038, 25956, 33551]

Should 178 now be ignored because 389 is lower than 1000?

> (sorry this is not homework question. I want to avoid looping, because I
> have 300K lines to parse through)

If you have to parse 300K lines you will need a loop. It may not be 
explicit but it will be there. Get used to that idea and worry about how 
you process the data. And maybe making sure you only loop over 
everything once!


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list