Elegant and cheap way to transform lists in python -
suppose have list of numbers i'd increment , i'm interested in incremented values, not original ones afterwards. pythonic way in situ, without copying list?
does
a = [1, 2, 3] = [i+1 in a]
result in intermediate copy of a
, or python interpreter optimize this?
unfortunately, python knowledge still superficial. mother tongue c++.
without copying list can this:
in [1]: = [1, 2, 3] in [2]: id(a) out[2]: 48701592 in [3]: in xrange(len(a)): # range(len(a)) python 3 ...: a[i] += 1 ...: in [4]: out[4]: [2, 3, 4] in [5]: id(a) out[5]: 48701592
Comments
Post a Comment