Re: List Behavior when inserting new items

2007-02-06 Thread Gigs_
[EMAIL PROTECTED] wrote: > On Jan 29, 7:57 pm, "Drew" <[EMAIL PROTECTED]> wrote: >> I'm looking to add an element to list of items, however I'd like to >> add it at a specific index greater than the current size: >> >> list = [1,2,3] >> list.insert(10,4) >> >> What I'd like to see is something like

Re: List Behavior when inserting new items

2007-01-29 Thread André Malo
* Paul McGuire wrote: >> py>def __init__(self, arg = []): >> py>self.__list = arg > > Please don't perpetuate this bad habit!!! "arg=[]" is evaluated at > compile time, not runtime, and will give all default-inited llists the > same underlying list. While this actually might be bad

Re: List Behavior when inserting new items

2007-01-29 Thread Bruno Desthuilliers
Drew a écrit : >>What is your actual usecase? >> >>diez > > > The issue is that I don't know how long the list will eventually be. How is this an issue ? Python's lists are not fixed-sized arrays. > Essentially I'm trying to use a 2D list to hold lines that I will > eventually print to the sc

Re: List Behavior when inserting new items

2007-01-29 Thread Drew
> > Is there any way to produce this kind of behavior easily?Hints: > >>> [None] * 5 > [None, None, None, None, None] > >>> [1, 2, 3, None] + [10] > [1, 2, 3, None, 10] > > HTH That is exactly what I was looking for. I'm actually working on some problems at http://codgolf.com. I find it helps

Re: List Behavior when inserting new items

2007-01-29 Thread Bruno Desthuilliers
Drew a écrit : > I'm looking to add an element to list of items, however I'd like to > add it at a specific index greater than the current size: > > list = [1,2,3] NB: better to avoid using builtins types and functions names as identifiers. > list.insert(10,4) > > What I'd like to see is somet

Re: List Behavior when inserting new items

2007-01-29 Thread [EMAIL PROTECTED]
On Jan 29, 1:10 pm, "Drew" <[EMAIL PROTECTED]> wrote: > > What is your actual usecase? > > > diezThe issue is that I don't know how long the list will eventually be. > Essentially I'm trying to use a 2D list to hold lines that I will > eventually print to the screen. Blank elements in the list wi

Re: List Behavior when inserting new items

2007-01-29 Thread Paul McGuire
> py>def __init__(self, arg = []): > py>self.__list = arg Please don't perpetuate this bad habit!!! "arg=[]" is evaluated at compile time, not runtime, and will give all default-inited llists the same underlying list. The correct idiom is: def __init__(self, arg = None):

Re: List Behavior when inserting new items

2007-01-29 Thread [EMAIL PROTECTED]
On Jan 29, 7:57 pm, "Drew" <[EMAIL PROTECTED]> wrote: > I'm looking to add an element to list of items, however I'd like to > add it at a specific index greater than the current size: > > list = [1,2,3] > list.insert(10,4) > > What I'd like to see is something like: > > [1,2,3,,4] > > However I

Re: List Behavior when inserting new items

2007-01-29 Thread Drew
> What is your actual usecase? > > diez The issue is that I don't know how long the list will eventually be. Essentially I'm trying to use a 2D list to hold lines that I will eventually print to the screen. Blank elements in the list will be printed as spaces. I suppose every time I add an elem

Re: List Behavior when inserting new items

2007-01-29 Thread Diez B. Roggisch
Drew schrieb: > I'm looking to add an element to list of items, however I'd like to > add it at a specific index greater than the current size: > > list = [1,2,3] > list.insert(10,4) > > What I'd like to see is something like: > > [1,2,3,,4] > > However I see: > > [1,2,3,4] > > Is there

List Behavior when inserting new items

2007-01-29 Thread Drew
I'm looking to add an element to list of items, however I'd like to add it at a specific index greater than the current size: list = [1,2,3] list.insert(10,4) What I'd like to see is something like: [1,2,3,,4] However I see: [1,2,3,4] Is there any way to produce this kind of behavior eas