Re: building a list provided the position of element is known
- To: mathgroup at smc.vnet.net
- Subject: [mg68032] Re: building a list provided the position of element is known
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Fri, 21 Jul 2006 05:37:17 -0400 (EDT)
- Organization: Uni Leipzig
- References: <e9nknv$9sn$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
place[what_, where_] :=
Module[{lst},
lst = Table[Null, {Max[where]}];
MapThread[
If[lst[[#2]] === Null, lst[[#2]] = #1,
lst[[#2]] = Flatten[Join[{lst[[#2]]}, {#1}]]]
&,
{what, where}];
lst /. Null -> _
]
and
place[{A, B}, {3, 4}]
place[{A, B}, {4, 4}]
Regards
Jens
PS. You are sure that {_,B,A} is a three
dimensional list,
and not a list of dimension three ??
"Arkadiusz Majka"
<Arkadiusz.Majka at telekomunikacja.pl> schrieb im
Newsbeitrag news:e9nknv$9sn$1 at smc.vnet.net...
| Hi,
|
| I have two elements, say A and B and their
positions in a three
| dimensional list. Eg {1,3} means that position
of A is 1 , position ob
| is 3 and a list is given {A,_,B}. {3,2}
corresponds to {_,B,A}, {3,3}
| corresponds to {_,_,{A,B}}.
|
| How can I code it in Mathematica using any
number of elements and a
| list of any length>0?
|
| Thx,
|
| Arek
|