Re: object's list index

2006-03-03 Thread William Meyer
Kent Johnson kentsjohnson.com> writes: > In either case enumerate() is your friend. To find an > item by identity: > > def index_by_id(lst, o): >for i, item in enumerate(lst): > if item is o: >return i >raise ValueError, "%s not in list" % o > > If you just want the index

Re: object's list index

2006-03-03 Thread William Meyer
Iain King gmail.com> writes: > what's wrong with: > > i = 0 > for object in list: > objectIndex = i > print objectIndex > i += 1 > > Iain > The issues with that is you might have a complex structure below the for object in list: with lots of continues or breaks and you don't want

object's list index

2006-03-03 Thread William Meyer
hi, I need to get the index of an object in a list. I know that no two objects in the list are the same, but objects might evaluate as equal. for example list = [obj1, obj2, obj3, obj4, obj5] for object in list: objectIndex = list.index(object) print objectIndex prints 0, 1, 2, 3, 2

Re: Shell Navigation

2006-03-02 Thread William Meyer
Simon Brunning brunningonline.net> writes: > Sounds like a readline problem. Your OS? How did you install Python? Yea, that was it. I just had to copy readline.so from another installation. Thanks for the quick reply -- http://mail.python.org/mailman/listinfo/python-list

Shell Navigation

2006-03-02 Thread William Meyer
I am having trouble with the python interactive shell. The arrow keys render as ^[[D, ^[[A, etc making line editing impossible. The arrow keys (and function keys) work fine in bash, but in the python shell they are printed. Any ideas what is going on? -- http://mail.python.org/mailman/listinfo/py

Re: comple list slices

2006-02-28 Thread William Meyer
gmail.com> writes: > Although I don't know if this is faster or more efficient than your > current solution, it does look cooler: > > def grouprows(inrows): > rows = [] > rows[:] = inrows # makes a copy because we're going to be > deleting > while len(rows) > 0: > rowspan

Re: comple list slices

2006-02-28 Thread William Meyer
gmail.com> writes: > > Python lets you iterate through a list using an integer index, too, > although if you do so we will make fun of you. You can accomplish it > with a while loop, as in: > > i = 0 > while i < len(rows): >if rows[i] == "This code looks like BASIC without the WEND, doesn

Re: comple list slices

2006-02-28 Thread William Meyer
gmail.com> writes: > > A couple questions: > > 1- what is j? > 2- what does the rows[x][y] object look like? I assume it's a dict > that has a "rowspan" key. Can rows[x][y]["rowspan"] sometimes be 0? > > Perhaps you're looking for something like this: > rowgroups = [] > rowspan = 0 > for i

comple list slices

2006-02-28 Thread William Meyer
Hi, I have a list of rows which contains a list of cells (from a html table), and I want to create an array of logical row groups (ie group rows by the rowspan). I am only concerned with checking the rowspan of specific columns, so that makes it easier, but I am having trouble implementing it in p