On Apr 7, 9:25 am, "mkPyVS" <[EMAIL PROTECTED]> wrote:
> On Apr 5, 6:37 pm, "John Machin" <[EMAIL PROTECTED]> wrote:
>
> >>> help(list.index)
> > Help on method_descriptor:
>
> > index(...)
> > L.index(value, [start, [stop]]) -> integer -- return first index
> > of value
>
> > I look forward to
On Apr 5, 6:37 pm, "John Machin" <[EMAIL PROTECTED]> wrote:
>>> help(list.index)
> Help on method_descriptor:
>
> index(...)
> L.index(value, [start, [stop]]) -> integer -- return first index
> of value
>
> I look forward to your next version.
Great point! I was assuming the temp variable spac
On Apr 6, 4:55 am, "mkPyVS" <[EMAIL PROTECTED]> wrote:
> Not sure below is better but it hacks at larger chunks (excuse the 10
> second coding)
> m = [2,9,1,5,6,3,1,1,9,2]
> f = 1
> temp = m
Overwritten 3 statements later
> location = m.index(f)
> gloc = location
> temp = m[location:]
> while 1:
Not sure below is better but it hacks at larger chunks (excuse the 10
second coding)
m = [2,9,1,5,6,3,1,1,9,2]
f = 1
temp = m
location = m.index(f)
gloc = location
temp = m[location:]
while 1:
print(temp)
try:
location = temp.index(f) + 1
gloc += location
except:
break
On Apr 5, 1:58 am, [EMAIL PROTECTED] wrote:
> For any list x, x.index(item) returns the index of the FIRST
> occurrence of the item in x. Is there a simple way to identify the
> LAST occurrence of an item in a list? My solution feels complex -
> reverse the list, look for the first occurence of the
Terry Reedy:
> def rindex(lis, item):
> for i in range(len(lis)-1, -1, -1):
> if item == lis[i]:
> return i
> else:
> raise ValueError("rindex(lis, item): item not in lis")
This is an alternative, I don't know if it's faster:
def rindex(seq, item):
for pos,
On 4 Apr 2007 08:58:49 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> For any list x, x.index(item) returns the index of the FIRST
> occurrence of the item in x. Is there a simple way to identify the
> LAST occurrence of an item in a list? My solution feels complex -
> reverse the list, look
"7stud" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| How about:
|
| l = [1, 2, 1, 3, 1, 5]
| target = 1
| for index, val in enumerate(l):
|if val==1:
|lastIndexOf = index
|
| print lastIndexOf
You might want to initialize lastIndexOf (to None, for instance).
If len(l
On Apr 4, 11:20 am, "7stud" <[EMAIL PROTECTED]> wrote:
> On Apr 4, 10:55 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
>
> > <[EMAIL PROTECTED]> wrote in message
>
> >news:[EMAIL PROTECTED]
> > | For any list x, x.index(item) returns the index of the FIRST
> > | occurrence of the item in x. Is there
On Apr 4, 10:55 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
> | For any list x, x.index(item) returns the index of the FIRST
> | occurrence of the item in x. Is there a simple way to identify the
> | LAST occurrence of an item in a
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| For any list x, x.index(item) returns the index of the FIRST
| occurrence of the item in x. Is there a simple way to identify the
| LAST occurrence of an item in a list? My solution feels complex -
| reverse the list, look for the firs
For any list x, x.index(item) returns the index of the FIRST
occurrence of the item in x. Is there a simple way to identify the
LAST occurrence of an item in a list? My solution feels complex -
reverse the list, look for the first occurence of the item in the
reversed list, and then subtract its in
12 matches
Mail list logo