MathGroup Archive 2000

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

Search the Archive

Re: Appending an element to a list


Felix,
    If the function output is always a singly-dimensioned list, the
following will work:

myAppend[l_List, m_List] := If[Length[m] == 0, l, Append[l, m] ];

d1 = {};
d2 = {a, b};
lst = {{2, 2}, {3, 3}};

In[74]:=
myAppend[lst, d2]
myAppend[lst, d1]

Out[74]=
{{2, 2}, {3, 3}, {a, b}}

Out[75]=
{{2, 2}, {3, 3}}

-mark harder

-----Original Message-----
From: Felix Farkas <farkas at icamail.epfl.ch>
To: mathgroup at smc.vnet.net
Subject: [mg23904] [mg23870] Appending an element to a list


>
>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
>
>
>
>



  • Prev by Date: Re: J/Link image display?
  • Next by Date: RE: Appending an element to a list
  • Previous by thread: Re: Appending an element to a list
  • Next by thread: RE: Appending an element to a list