Question: When a list is sliced, are the references to its contents copied from the original list? I can imagine that this may not be necessary, but I read the opposite ([mentioned in passing](https://stackoverflow.com/a/5131563/42973)).

This question matters for instance for the following idiom, in the case of a very long `my_list`:

```
for (first_elmt, second_elmt) in itertools.izip(my_list[:-1], my_list[1:]):
    …

```

A copy would use up both memory and, presumably, some time. I compared to looping over the index of `first_elmt` with `xrange()`, on a list of 100 million integers. The slicing approach is actually 20% faster, but does seem to copy references (the system time is longer). Is this indeed the case?

**PS**: I now realize that it is quite natural that slices copy the references: if the original list is modified, the slice does not change, so it is easier to have the implementation of the slice copy the references of the original list. A pointer to the CPython implementation would be interesting, though.

Answer: 
Slicing will copy the references. If you have a list of 100 million things:

```
l = [object() for i in xrange(100000000)]

```

and you make a slice:

```
l2 = l[:-1]

```

`l2` will have its own backing array of 99,999,999 pointers, rather than sharing `l`'s array. However, the objects those pointers refer to are not copied:

```
>>> l2[0] is l[0]
True

```

If you want to iterate over overlapping pairs of elements of a list without making a copy, you can `zip` the list with an iterator that has been advanced one position:

```
second_items = iter(l)
next(second_items, None) # Avoid exception on empty input
for thing1, thing2 in itertools.izip(l, second_items):
    whatever()

```

This takes advantage of the fact that `zip` stops when any input iterator stops. This can be extended to cases where you're already working with an iterator using [`itertools.tee`](https://docs.python.org/2/library/itertools.html)

```
i1, i2 = itertools.tee(iterator)
next(i2, None)
for thing1, thing2 in itertools.izip(i1, i2):
    whatever()

```
Yes, slicing DO copy references, in fact, it is an idiom to make copy of a list this way: `newlst = lst[:]`.