A simple list question.
Larry Bates
larry.bates at websafe.com
Thu Dec 22 15:59:59 EST 2005
KraftDiner wrote:
> Is there a cleaner way to implement this code?
>
> if len(self.listOfObjects) == 0:
> self.listOfObjects.append(self.currentObject)
> elif:
> self.listOfObjects[self.currentSlice] = self.currentObject
>
> listOfObjects is a list of lists....
> If the listOfObjects is [] then I have to use append to add the first
> list
> otherwise I can access each list using the index into the list.
>
It appears you are trying to do two different things in one if
statement and it is unclear where self.currentSlice comes from.
You also need a condition on your elif. Perhaps more explanation
is needed (at least for me to help).
-Larry Bates
More information about the Python-list
mailing list