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: [mg115110] Re: Manually culling a list
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 31 Dec 2010 04:59:36 -0500 (EST)

Actually, I don't think that does the job.

a) When checking items in the "checks" list, you can't see the items in  
"list" that you're selecting.

b) It involves manually listing variables a, b, c... to match the list,  
which isn't very flexible.

c) You cannot run

checks = Map[Composition[Checkbox, Dynamic], selected]

a second time to create a different culled list or to cull it further.

The following solves those problems:

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

Grid@{list,
   checks = Map[Composition[Checkbox, Dynamic], Unique /@ list]}

selected = checks /. {Checkbox -> Identity, Dynamic -> Identity}

{True, False, True, False, False, True}

cull1 = Pick[list, selected]

{"A", "C", "F"}

Partition[Riffle[list, selected], 2]

{{"A", True}, {"B", False}, {"C", True}, {"D", False}, {"E",
   False}, {"F", True}}

To further cull the list:

Grid@{cull1,
   checks = Map[Composition[Checkbox, Dynamic], Unique /@ cull1]}

selected = checks /. {Checkbox -> Identity, Dynamic -> Identity}

{False, True, True}

cull2 = Pick[cull1, selected]

{"C", "F"}

Partition[Riffle[cull1, selected], 2]

{{"A", False}, {"C", True}, {"F", True}}

Bobby

On Thu, 30 Dec 2010 18:07:18 -0600, Zach Bjornson <bjornson 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
>>
>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Manually culling a list
  • Next by Date: Re: Manually culling a list
  • Previous by thread: Re: Manually culling a list
  • Next by thread: Re: Manually culling a list