Steven D'Aprano wrote:
> On Tue, 07 Mar 2006 12:26:00 -0800, James Stroud wrote:
>
>
>>John Salerno wrote:
>>
>>>Diez B. Roggisch wrote:
>>>
>>>
Why don't you just _try_ that? It would have been way faster than to ask
questions you can easily answer yourself.
>>>
>>>
>>>I did try it, but
On Tue, 07 Mar 2006 12:26:00 -0800, James Stroud wrote:
> John Salerno wrote:
>> Diez B. Roggisch wrote:
>>
>>> Why don't you just _try_ that? It would have been way faster than to ask
>>> questions you can easily answer yourself.
>>
>>
>> I did try it, but I was still hoping for an explanation
James Stroud wrote:
> Here is one my favorite examples of python intuitiveness:
>
> if something is not something_else:
> do_whatever()
>
> Who would have thunk it?
That's actually one of the things that first surprised me about Python,
that you can actually say "is not" in a programming lan
John Salerno wrote:
> Diez B. Roggisch wrote:
>
>> Why don't you just _try_ that? It would have been way faster than to ask
>> questions you can easily answer yourself.
>
>
> I did try it, but I was still hoping for an explanation, which I've also
> gotten from you guys, some in nicer terms tha
Warby wrote:
> It makes sense because a slice IS a list, so you should assign a list
> to it. Yours is just a special case in which the target slice has a
> length of zero. It's still a list, just an empty one:
>
L = [1,2,4]
print L[2:2]
> []
>
> As for your question, yes:
>
L =
Diez B. Roggisch wrote:
> John Salerno wrote:
>
>> Diez B. Roggisch wrote:
>>
>>> Why don't you just _try_ that? It would have been way faster than to ask
>>> questions you can easily answer yourself.
>> I did try it, but I was still hoping for an explanation, which I've also
>> gotten from you gu
John Salerno wrote:
> Diez B. Roggisch wrote:
>
>> Why don't you just _try_ that? It would have been way faster than to ask
>> questions you can easily answer yourself.
>
> I did try it, but I was still hoping for an explanation, which I've also
> gotten from you guys, some in nicer terms than o
Diez B. Roggisch wrote:
> Why don't you just _try_ that? It would have been way faster than to ask
> questions you can easily answer yourself.
I did try it, but I was still hoping for an explanation, which I've also
gotten from you guys, some in nicer terms than others.
--
http://mail.python.or
It makes sense because a slice IS a list, so you should assign a list
to it. Yours is just a special case in which the target slice has a
length of zero. It's still a list, just an empty one:
>>> L = [1,2,4]
>>> print L[2:2]
[]
As for your question, yes:
>>> L = [1,2,4]
>>> L[2:2] = [[3]]
>>>
John Salerno wrote:
> Christoph Haas wrote:
>> L[2:2]=[3]
[ ... ]
What if you wanted to insert an actual list into that
slot? Would
> you have to wrap it in double brackets?
Yep.
It's a strong-typing thing. Slices of lists are lists, and
therefore what you assign to one has got to be a list,
John Salerno wrote:
> Christoph Haas wrote:
>
>> L[2:2]=[3]
>
> I'm still a little confused about this. If what I'm inserting is just an
> integer, why wouldn't
> L[2:2] = 3
>
> work?
Because a slice represents a list - even if it is a one-elemented one. So,
replacing it you need another list
Christoph Haas wrote:
> L[2:2]=[3]
I'm still a little confused about this. If what I'm inserting is just an
integer, why wouldn't
L[2:2] = 3
work? What if you wanted to insert an actual list into that slot? Would
you have to wrap it in double brackets?
--
http://mail.python.org/mailman/listi
Diez B. Roggisch wrote:
l = [1,2,3]
l.insert(2, 10)
l
> [1, 2, 10, 3]
>
> Embarrasing enough?
Actually, I was trying to figure it out with the slice technique
instead. But yeah, as Christopher's example showed, it's not hard. But I
didn't realize you had to assign a list item to
from the Library Reference:s.insert(i, x)
same as s[i:i] = [x]
(5)On 3/7/06, John Salerno <[EMAIL PROTECTED]
> wrote:Let me apologize in advance for what I'm sure is an achingly simple
question, but I just can't find the answer in either of my Python books.I've tried a few tests wit
John Salerno wrote:
> Let me apologize in advance for what I'm sure is an achingly simple
> question, but I just can't find the answer in either of my Python books.
> I've tried a few tests with the interactive prompt, but they don't work
> either.
>
> All I'm trying to do is insert an item into
On Tuesday 07 March 2006 16:18, John Salerno wrote:
> Let me apologize in advance for what I'm sure is an achingly simple
> question, but I just can't find the answer in either of my Python books.
> I've tried a few tests with the interactive prompt, but they don't work
> either.
>
> All I'm trying
Let me apologize in advance for what I'm sure is an achingly simple
question, but I just can't find the answer in either of my Python books.
I've tried a few tests with the interactive prompt, but they don't work
either.
All I'm trying to do is insert an item into a list, like so:
L = [1, 2, 4
17 matches
Mail list logo