MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Appending an element to a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23943] RE: [mg23880] Appending an element to a list
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 16 Jun 2000 00:57:30 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com


> -----Original Message-----
> From: Felix Farkas [mailto:farkas at icamail.epfl.ch]
To: mathgroup at smc.vnet.net
> 
> Hello,
>  i do have a problem, which is probably very easy,  but i couldn't find
> a reasonable way to solve it. I would appreciate very much any hint.
> 
> I have a list of lists. My purpose is to append a new elements to this
> list. These elements are generated by some function. Sometimes the
> output of the function is an empty list meaning no element. In this
> situation Append includes the new element in the list. i would like to
> avoid this behaviour.
> 
> ex:
> 
> In[1]:=           d={}
> Out[1]=         {}
> 
> In[2]:=           Append[{{2,2},{3,3}},d]
> Out[2]:=        {{2,2},{3,3},{}}
> 
> 
> Thanks in advance. Felix Farkas
> 

Felix,

Your could do this (Sequence[] disappears from a list of items):

Append[{{2, 2}, {3, 3}}, {}] /. {} -> Sequence[]

or define your own Append function:

myAppend[l_, element_] := If[Length[element] > 0, Append[l, element], l]

myAppend[{{2, 2}, {3, 3}}, {}]
{{2, 2}, {3, 3}}

myAppend[{{2, 2}, {3, 3}}, {4, 4}]
{{2, 2}, {3, 3}, {4, 4}}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/ 


  • Prev by Date: Re: Appending an element to a list
  • Next by Date: Re: Monte Carlo in Mathematica ?
  • Previous by thread: Re: Appending an element to a list
  • Next by thread: Re: Appending an element to a list