help retrieving / storing info in dictionary or gadfly

Emile van Sebille emile at fenx.com
Mon Jan 15 07:06:46 EST 2001


I needed this recently and ended up adding an "rindex"
method to lists in listobject.c.  It works like index, but
adds <= , < , > and => selection qualifiers.  I don't have
time this morning, but if you're interested and are
compiling from source, email me and I'll send you the
changes I made.

usage example:

I have a sorted list of strings that contain YYMMDD in [:6].
This function returns the slice for that day from the source
list of strings.

def pickOffDay(srce, cmpDt):
 idx = srce.rindex(cmpDt, 2)
 dtLen = srce[idx:].rindex(cmpDt, 1)
 return srce[idx:idx+dtLen]

>From the source code:

L.rindex(value, cmp) -> integer -- return index of first
occurrence of value
 where cmp is
 -2 - less than or equal
 -1 - less than
  0 - equal (same as current index)
  1 - greater than
  2 - greater than or equal";

--

Emile van Sebille
emile at fenx.com
-------------------


"Bryan Webb" <bww00 at amdahl.com> wrote in message
news:93u48n$65t at dispatch.concentric.net...
> Hello,
>     I have a dictionary that has records with keys from 1
to 2^128
> I can build a list and sort the keys in order, then search
thru the list of
> sorted keys.
>     If the list has 1,2,3,4,5,7,8,9 and I need to search
for 6. 6 is not in
> the list , so I need the record that is closest to 6 but
not greater than 6.
> Is there a way to further index the list of keys to do
this ?
>
> Could I use GADFLY to do this.
>
>
> Any ideas and help would be appreciated.
>
> Thanks
> bryan Webb
>
>





More information about the Python-list mailing list