Weird behavior in search in a list
- From: "Su Y" <suyuancn@xxxxxxxxx>
- Date: 29 Mar 2007 04:51:00 -0700
hi all,
I can't understand how this code work, its behavior is really weird
for me...
I want find the first number in extend[] which is larger than num, so
I wrote:
def find(num):
count=0
for elem in extend:
if elem<num:
count+=1
return count
I found that if extend[] is monotonous, like [1.1, 2.3, 3.2, 4.5,
5.6],
it works fine: find(4) returns 3, extend[3] is 4.5.
But, if extend[] is not monotonous, like [1.1, 2.3, 3.2, 4.5, 5.6,
4.6, 3.4, 2.1, 0.3],
find(4) returns 6, extend[6] is 3.4!
what's going on here? I really can't understand....
.
- Follow-Ups:
- Re: Weird behavior in search in a list
- From: Hendrik van Rooyen
- Re: Weird behavior in search in a list
- From: Michael Bentley
- Re: Weird behavior in search in a list
- From: Amit Khemka
- Re: Weird behavior in search in a list
- From: Su Y
- Re: Weird behavior in search in a list
- Prev by Date: Re: newbi question on python rpc server, how it works?
- Next by Date: Re: BeautifulSoup vs. Microsoft
- Previous by thread: YouTube showing repr() of a tuple
- Next by thread: Re: Weird behavior in search in a list
- Index(es):
Relevant Pages
|
|