<div dir="ltr"><div dir="ltr"><div>Hi Julien,</div><div>Thank you for your answer. Cristal clear your explanation! I understand now what I was doing wrong, thanks very much!</div><div>Best regards</div><div>Jorge Minguet<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El mié., 22 may. 2019 a las 6:29, Julien Palard (<<a href="mailto:julien@palard.fr">julien@palard.fr</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Jorge,<br>
<br>
> just to report last lines results seems to obtain some extra numbers. it may be a bug<br>
<br>
Slices in Python starts with an inclusive bound and end with an exclusive bound.<br>
Quoting the documentations, s[i:j] is:<br>
> The slice of s from i to j is defined as the sequence of items with index k such that `i <= k < j`<br>
<br>
Given:<br>
<br>
    alist = list(range(10))<br>
<br>
We can see that:<br>
<br>
    >>> alist[2:5]<br>
    [2, 3, 4]<br>
    >>> alist[5:2]<br>
    []<br>
<br>
Note that the second one, "from 5 to 2" is empty, yet starts at position 5, so when we assign to it, it will "erase" no values, yet have a place to put new values:<br>
<br>
In this case, we're replacing all items of index k such as 2 <= k < 5, so index 2, 3, 4, so we're replacing 3 items by two items, the resulting length is 9:<br>
<br>
    >>> alist = list(range(10))<br>
    >>> alist[2:5] = 'a', 'b'<br>
    >>> alist<br>
    [0, 1, 'a', 'b', 5, 6, 7, 8, 9]<br>
<br>
Here we're replacing all items of index k such as 5 <= k < 2, which can't exist, so we're replacing 0 items by two items, the resulting length is 12, note that they are not inserted randomly, they are inserted at the index where the empty slice starts:<br>
<br>
    >>> alist = list(range(10))<br>
    >>> alist[5:2] = 'a', 'b'<br>
    >>> alist<br>
    [0, 1, 2, 3, 4, 'a', 'b', 5, 6, 7, 8, 9]<br>
<br>
In your example:<br>
<br>
>>> v = []<br>
>>> v[0:5]=6,7,8,9,0<br>
>>> v[-1]=6,7<br>
>>> v<br>
[6, 7, 8, 9, (6, 7)]<br>
>>> v[-1:-5]  # An empty slice, so assigning to it will only add elements at position -1<br>
[]<br>
>>> v[-1:-5]='a','b','c','d','e'<br>
>>> v<br>
[6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', (6, 7)]<br>
>>> v[-5:-1]  # A non empty slice, so assigning to it will replace b, c, d, and e with A, B, C, D and E<br>
['b', 'c', 'd', 'e']<br>
>>> v[-5:-1]='A','B','C','D','E'<br>
>>> v<br>
[6, 7, 8, 9, 'a', 'A', 'B', 'C', 'D', 'E', (6, 7)]<br>
<br>
Does it helps?<br>
<br>
Bests,<br>
-- <br>
Julien Palard<br>
<a href="https://mdk.fr" rel="noreferrer" target="_blank">https://mdk.fr</a><br>
<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Saludos cordiales,<div>Jorge Minguet</div></div></div></div>