I want to create a list with ramp values from a list with non-ramp values in Python. for instance
input =[10,10,10,6,6,4,1,1,1,10,10]
should be converted to:
output=[0,0,0,1,1,2,3,3,3,0,0]
My code uses a python dictionary
def linearize(input):
"""
Remap a input list containing values in non linear-indices list
i.e.
input = [10,10,10,6,6,3,1,1]
output= [0,0,0,1,1,2,3,3]
"""
remap={}
i=0
output=[0]*len(input)
for x in input:
if x not in remap.keys():
remap[x]=i
i=i+1
for i in range(0,len(input)):
output[i]=remap[input[i]]
return output
but I know this code may be more efficient. Some ideas to make this task a better and more pythonic way is an option? This function must be called very often on large lists.