Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10778 > unrolled thread

Re: case of inconsistent API between Drop and Part?

Started byJason Ebaugh <ebaughjason@gmail.com>
First post2012-07-04 07:33 +0000
Last post2012-07-04 07:33 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: case of inconsistent API between Drop and Part? Jason Ebaugh <ebaughjason@gmail.com> - 2012-07-04 07:33 +0000

#10778 — Re: case of inconsistent API between Drop and Part?

FromJason Ebaugh <ebaughjason@gmail.com>
Date2012-07-04 07:33 +0000
SubjectRe: case of inconsistent API between Drop and Part?
Message-ID<jt0rke$1e5$1@smc.vnet.net>
> Use one call to Drop to remove only elements
> 
>        2,3,7,11, and 12
> 
> from
> 
> lis={q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m}


This will do the trick:

list = {q, w, e, r, t, y, u, i, o, p, a, s, d, f, g, h, j, k, l, z, x, c, v, b, n, m};

ElementsToRemove = {2, 3, 7, 11, 12};
ElementsToRemove = Table[Rule[element, Null], {element, ElementsToRemove}]

Out[]= {2 -> Null, 3 -> Null, 7 -> Null, 11 -> Null, 12 -> Null}


DeleteCases[ReplacePart[list, ElementsToRemove], Null]

Out[]= {q, r, t, y, i, o, p, d, f, g, h, j, k, l, z, x, c, v, b, n, m}


The above can be put together into one function:

DropElements[list_, elementstoremove_] := 
 DeleteCases[
  ReplacePart[list, 
   Table[Rule[element, Null], {element, elementstoremove}]], Null]


newlist = CharacterRange["a", "z"]

Out[]= {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", \
"m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}


NewElementsToRemove = {1, 4, 5, 9, 10, 11, 13, 20, 25};


DropElements[newlist, NewElementsToRemove]

Out[]= {"b", "c", "f", "g", "h", "l", "n", "o", "p", "q", "r", "s", "u", "v", "w", "x", "z"}



Using the Null intermediate is a bit sloppy. But this will at least get you going in the right direction to make a more solid version. 



Jason Ebaugh

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web