[Tutor] mapping/filtering a sequence

kevin parks kp8 at mac.com
Fri Sep 4 19:31:02 CEST 2009


I am doing some data massage, minor mapping and filtering really and i  
find that i have a lot of this kind of kludgy code:

# -- -------------------------
def filt_seq(inseq):
	out_list = []
	for item in inseq:
		# 38 needs to be mapped on to 34 as we don't have a 38 in our grid
		if item == 38:
			item = item - 4
			out_list.append(item)
		# We also don't have a 40, but we do have a 39. Map that sucka
		elif item == 40:
			item = item - 1
			out_list.append(item)
		# if we get values that fall in good places, just pass them on to  
the out seq
		else:
			out_list.append(item)
	return out_list

# -- -------------------------

To do some basic jiggering of some out of range off grid data.

There has to be a better, more elegant, more flexible less brute force  
more pythonic way to do this kind of mapping no?

cheers,

-kp--




More information about the Tutor mailing list