So I have a list D = [[1030, 1200], [1300, 1600], [1800, 1830]]
and I made a copy called E: E = D[:]
then I tried to operate on it with a function: covertToMin(E)
. However the function also operated on D
which doesn't make sense because they have separate locations in memory.
I am pretty confused and appreciate any help!
E = D[:]
for i in range(len(E)):
for j in range(0,2):
E[i][j] = convertToMinutes(E[i][j])
print(id(E))
print(id(D))
print(D)
print(E)
def convertToMinutes(time):
if time < 1000:
time = str(time)
minutes = time[1:]
hourmin = int(time[0])* 60
time = int(minutes) + (hourmin)
else:
time = str(time)
minutes = time[2:]
hourmin = int(time[:2]) * 60
time = int(minutes) + hourmin
return time
The output I receive is:
4368232032
4368231552
[[690, 720], [900, 960], [1080, 1110]]
[[690, 720], [900, 960], [1080, 1110]]