Re: [Tutor] mapping/filtering a sequence

2009-09-09 Thread kevin parks
Prolly good to post final solutions for future goog'lerz (like when i forget) or anyone who was following along. Here's where i ended up with this... shows both ways. -- #!/usr/bin/env python my_map = { 38:34, 40:39, 45:44, 47:46, 52:51, 59:58, 55:56 } def filter_item(item): retu

Re: [Tutor] mapping/filtering a sequence

2009-09-06 Thread kevin parks
I actually find the map biz easier to get my head around than the list comp. I guess this makes it another good reason for me to be happy that map is apparently staying in after nearly being depreciated. I generally prefer list comp in every instance, but the idea of an if else construct wi

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread Wayne
On Sat, Sep 5, 2009 at 10:21 AM, kevin parks wrote: > > Then what you would want to do is map the data to the nearest value no? I guess it all depends on your desired level of precision! > For this particular hack, I am mostly getting useful values in the range > 30-85, so I am filtering out

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread Mark Tolonen
"Douglas Philips" wrote in message news:9ee00578-6af7-4c6c-9968-af5f25a00...@mac.com... On 2009 Sep 5, at 12:22 PM, Mark Tolonen wrote: As a list comp: L=range(30,41) [{38:34,40:39}.get(n,n) for n in L] [30, 31, 32, 33, 34, 35, 36, 37, 34, 39, 39] True, that is terse, but IMHO has maint

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread kevin parks
Yeah the list seems flaky at the moment. Additionally, my query is an incredibly stupid one. But what you have works and represents an improvement over the unreadable kludge I was doing. Thanks to all who responded. cheers, k On Sep 6, 2009, at 12:26 AM, Douglas Philips wrote: On or ab

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread kevin parks
I can think of about 80 billion reasons why you would encounter data outside your grid, esp. if you aren't the original producer of the data. Imagine you are mapping something to color (RGB values) or you are doing a signification of volcanic activity or the big bang or the earth's magnetic

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread Douglas Philips
On 2009 Sep 5, at 12:22 PM, Mark Tolonen wrote: As a list comp: L=range(30,41) [{38:34,40:39}.get(n,n) for n in L] [30, 31, 32, 33, 34, 35, 36, 37, 34, 39, 39] True, that is terse, but IMHO has maintainability issues. The mapping data structure and the method of transformation (.get()) ar

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread Mark Tolonen
"Douglas Philips" wrote in message news:6a3250c7-31b6-4958-8e0a-f538989ed...@mac.com... On or about 2009 Sep 5, at 10:45 AM, Martin A. Brown indited: Have you discovered the map() builtin yet? I would imagine that others on this list will have some even more elegant and efficient solutions f

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread Douglas Philips
On or about 2009 Sep 5, at 10:45 AM, Martin A. Brown indited: Have you discovered the map() builtin yet? I would imagine that others on this list will have some even more elegant and efficient solutions for you, but here's a possibility: def filt_seq( thing ): if thing == 38: thing = t

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread Martin A. Brown
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 : 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: :

Re: [Tutor] mapping/filtering a sequence

2009-09-05 Thread Wayne
On Fri, Sep 4, 2009 at 12:31 PM, kevin parks wrote: > 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: > > To do some basic jiggering of some out of range off grid data. > > There has to be a better, more elegant, more f