Aliasing

In [2]:
lista = [4, 2, 1, 3]
listb = lista
lista.sort()
print lista
print listb
[1, 2, 3, 4]
[1, 2, 3, 4]
In [4]:
print id(lista)
print id(listb)
140157595946952
140157595946952
In [6]:
import numpy as np

def get_sorted_cumsum(numbers):
    numbers.sort()
    cum_sum = np.cumsum(numbers)
    return cum_sum

mynumbers = [5, 2, 1, 3, 3, 2, 5, 4, 1, 1]
sorted_cumsum = get_sorted_cumsum(mynumbers)
print mynumbers
[1, 1, 1, 2, 2, 3, 3, 4, 5, 5]
In [7]:
lista = [4, 2, 1, 3]
listb = lista[:]
lista.sort()
print lista
print listb
[1, 2, 3, 4]
[4, 2, 1, 3]