Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Manually culling a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115112] Re: Manually culling a list
  • From: ntg <ntgladd at gmail.com>
  • Date: Fri, 31 Dec 2010 04:59:59 -0500 (EST)
  • References: <ifhi9c$i2o$1@smc.vnet.net> <ifj6rr$5em$1@smc.vnet.net>

On Dec 30, 4:07 pm, Zach Bjornson <bjorn... at stanford.edu> wrote:
> Hi,
>
> In[1]:= list = CharacterRange["A", "F"]
> Out[1]= {"A", "B", "C", "D", "E", "F"}
>
> In[2]:= selected = {a, b, c, d, e, f};
>
> In[3]:= checks = Map[Composition[Checkbox, Dynamic], selected]
> Out[3]:= (*Checkboxes appear here*)
>
> In[4]:= culledlist = Dynamic@Pick[list, selected]
>
> Out[4]= (*Dynamic list of selected items appears here*)
>
> (*The list in the format you described*)
> In[5]:= Partition[Riffle[list, selected], 2]
> Out[5]= {{"A", True}, {"B", True}, {"C", True}, {"D", False}, {"E",
>    True}, {"F", False}}
>
> Cheers,
> Zach
>
> On 12/30/2010 1:10 AM, ntg wrote:
>
> > Hello guys,
>
> > Suppose I have a longish list of items that I want to manually cull.
> > It seems I should be able to do something like
>
> > checkList = ({Checkbox[], #)&  /@ list
>
> > Then, I could write
>
> > instanceOfCheckList = checkList
>
> > check away, and hopefully see something like
>
> > {{True, item1}, {False, item2}, ...}
>
> > which I could manipulate. But all I see is the the list of "checked"
> > checkboxs and items, not the consequence of checking the boxes. I can
> > do a FullForm on instanceOfCheckList and extract what I need via list
> > surgery-- but that is inelegant. I'm sure there is some magic
> > incantation involving Evaluate or Interpretation or Dynamic. Can you
> > help?
>
> > Thanks,
> > Tom

Thanks much to Tom and Zach,
I was able to extend Zach's approach and achieve what I needed.

Clear[MakeCheckList];
MakeCheckList[itemList_] :=
 Module[{boxList},
  VARS = Table[Unique[], {Length[itemList]}];
  boxList = Checkbox[Dynamic[#]] & /@ VARS;
  Grid[Transpose[{boxList, itemList}]]]

list = CharacterRange["A", "F"];

MakeCheckList[list]

The above displays a grid with paired checkboxes and items  (I needed
to see the items to decide which to select )
I check the boxes paired with items B and E.

Then, the operation
Dynamic@Pick[list, VARS]

displays
{B, E}

This works for me -- but it would be nice to encapsulate all of the
steps within a function that returns the culled list.

Happy New Year,
Tom



  • Prev by Date: Re: How to turn off curly quotes in Mathematica 8?
  • Next by Date: Re: Manually culling a list
  • Previous by thread: Re: Manually culling a list
  • Next by thread: Re: Manually culling a list