[Tutor] Binary chop function - this works, but I'm not sure why
Chris Fuller
cfuller084 at thinkingplanet.net
Thu Feb 14 02:10:49 CET 2008
On Wednesday 13 February 2008 18:49, Arun Srinivasan wrote:
> I'm trying to learn Python, and I decided to try kata 2 </> from the
> CodeKate website. It's basically just a challenge to implement a binary
> search in different ways.
>
> I wrote an implementation that works, but I'm confused as to why.
>
> def chop(search_int, sorted_list):
> if len(sorted_list) == 1 or 2:
This condition is always true. You meant to say: len(sorted_list) == 1 or
len(sorted_list) == 2"
or: "len(sorted_list) in 1,2"
Cheers
More information about the Tutor
mailing list