[Tutor] List action
Max Noel
maxnoel_fr at yahoo.fr
Sun Oct 3 17:05:44 CEST 2004
On Oct 3, 2004, at 15:49, kumar s wrote:
> I wrote a function that looks like following:
>>>> def element(x):
> for i in x:
> i.split()
>
>
>>>> k = element(qval)
>>>> k
>
> I get nothing in this K. It is empty.
That's because your function returns nothing. I would do this with a
list comprehension:
k = [i.split() for i in x]
> 2. After getting a file with all lists in a format
> like this:
> ['0.000100848', '0.02449766', '1']
> ['0.000109613', '0.02608342', '1']
> ['0.000113775', '0.02653233', '1']
> ['0.000143877', '0.03273097', '1']
> ['0.00014597', '0.03273097', '1']
> ['0.000149585', '0.0329087', '1']
> ['0.000159045', '0.03434194', '1']
> ['0.000176115', '0.03696072', '1']
>
> How do I write each element into a tab delimited text
> file.
It's not very hard. Here's how you would output this to the standard
out:
for line in k:
print '\t'.join(line)
Just redirect the standard out to the file you want to store the data
in. If you want the program itself to write the file, it's just a
matter of opening the file in write mode, then writing to it instead of
printing the data.
-- Wild_Cat
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting
and sweating as you run through my corridors... How can you challenge a
perfect, immortal machine?"
More information about the Tutor
mailing list