splitting tables

robsom no.mail at no.mail.it
Mon Feb 9 20:25:54 EST 2004


Sorry guys, I thank all of you, but I'm a beginner and my knowledge of
Python is not yet enough to follow you.

>>>> for line in s:
> ...print ','.join(map(lambda dat: dat != '-9999' and dat or '', line.split()))
> ... 

As far as I understand you are using a 'map' function to apply the
function "lambda dat: dat != '-9999' and dat or ''" to the elements
obtained with "line.split()".
First question: shouldn't it be split(line)?
Now, my book says that lambda works by applying (in this example) the
instructions in "dat != '-9999' and dat or ''" to the dat variable. Does
this mean that (I'm more or less guessing now) this code splits the line
assign each element to a dat variable which could have three types of
value (i.e. its "normal" value or -9999 or a space)? And then you use a
join functions to put again together the elements yolu have separated with
map with a comma as separator? And here I have a second question:
shouldn't it be "join(map(....),',')" instead of "','.join(map(...))"?

> I used here your -9999 as value of a mssing item.  Before you map that
> function across the splitted line you culd check for the correct length
> to see if you have e.g. like here always two coulmns.  If the length
> differs it depends if it's possible to find programmatically the missing
> column and just insert a space or something other.

Ok, but before going on, I'd like to know if I understand the code.
Probably I got it all wrong, but this is quite a few chapters beyond where
I am now in my book :)
Morevoer I wonder if it is possible to achieve the same thing  without
using the functional programming.

many thanks again

R



More information about the Python-list mailing list