[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
* 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
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
> > 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
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
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
> 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):
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
> 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
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
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
11 matches
Mail list logo