How can I repeat elements in place in an array in Python? -
how can repeat elements in place in array in python?
or similarly, more simple this:
drange = []; in xrange(j): drange.append(i); drange.append(i);
it should produce: [0, 0, 1, 1, 2, 2, ... j-1, j-1]
>>> j = 3 >>> drange = [] >>> in xrange(j): ... drange.extend([i]*2) ... >>> drange [0, 0, 1, 1, 2, 2]
or list comprehension
>>> drange = [i in xrange(j) k in range(2)] >>> drange [0, 0, 1, 1, 2, 2]
in cases method can appropriate
>>> drange = [i//2 in xrange(j*2)] >>> drange [0, 0, 1, 1, 2, 2]
python
No comments:
Post a Comment