Re: outputting lists
- To: mathgroup at smc.vnet.net
- Subject: [mg9874] Re: [mg9836] outputting lists
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Sat, 29 Nov 1997 00:11:02 -0500
- References: <199711281035.FAA10862@smc.vnet.net.>
- Sender: owner-wri-mathgroup at wolfram.com
[mg9836] outputting lists
Zahir Bishnani <zahir.bishnani at tao.j-sainsbury.co.uk> wrote
> Suppose I have a mathematica list that represents a number of
> n-dimensional vectors. e.g. {{2,3},{3,2},{6,5},{7,7},{1,1}}
> which represents five 2d vectors.
>
> Does anyone know an easy way of outputting this list to a file so that
> each line contains just a single n-dim vector with elements seperated
> by either spaces or commas.
> e.g. for the above example the file should be:
>
> 2 3
> 3 2
> 6 5
> 7 7
> 1 1
>
> Or
>
> 2,3
> 3,2
> 6,5
> 7,7
> 1,1
>
> thanks,
>
> Zahir
Zahir:
lst ={{2,3},{3,2},{6,5},{7,7},{1,1}};
ff = OpenWrite["ff"];
Apply[WriteString[ff, #1,",",#2,"\n"]&,lst,1];
!!ff
2,3
3,2
6,5
7,7
1,1
Apply[WriteString[ff, #1," ",#2,"\n"]&,lst,1];
!!ff
2,3
3,2
6,5
7,7
1,1
2 3
3 2
6 5
7 7
1 1
To avoid output we can use Scan:
Scan[(WriteString[ff, #1," ",#2,"\n"]&)@@#&,lst]
!!ff
2,3
3,2
6,5
7,7
1,1
2 3
3 2
6 5
7 7
1 1
2 3
3 2
6 5
7 7
1 1
--
Allan Hayes
Mathematica Training and Consulting
Leicester, UK
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 4198
- References:
- outputting lists
- From: Zahir Bishnani <zahir.bishnani@tao.j-sainsbury.co.uk>
- outputting lists