MathGroup Archive 2006

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

Search the Archive

Re: Any simple way to flatten all but the bottom level?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72379] Re: Any simple way to flatten all but the bottom level?
  • From: "wouter meeussen" <wouter.meeussen at pandora.be>
  • Date: Sat, 23 Dec 2006 06:14:38 -0500 (EST)
  • References: <emb4dh$950$1@smc.vnet.net>

generalising:

it takes some care to operate on the lowest level where the head "List"
occurs:
without assurance that the element count will always be three, and without
knowing that all elements will be atoms (but could also be "h[0]"), we can
still use:

li = {{0, 0, 0}, {{0, 0, 13}, {0, 1, 9}, {0, 2, 5},{0, 2, 5}, {0, 3, 1}},
{{1, 0, 4}, {1, 1, h[0]}}};

Flatten[li /. {expr__} :> (z[expr] /; FreeQ[z[expr], List])] /. z -> List

where we explicitly check for "List" on the lowest level.
dontdont@gmail has a point: Flatten could have been constructed working
'from bottom level up' just as well as the implemented 'from top level
down'. But it doesn't.

W.


  • Prev by Date: Re: terminate the NestWhile
  • Next by Date: Re: Tabling
  • Previous by thread: Re: Any simple way to flatten all but the bottom level?
  • Next by thread: Re: Any simple way to flatten all but the bottom level?