How can one infer from that list a list of its members that contain given elements, e.g. a list of members that contain b, or those that contain both b and c? For illustration:
Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}
I keep thinking there must be a direct way to do this using Select or some other function?
> How can one infer from that list a list of its members that contain > given elements, e.g. a list of members that contain b, or those that > contain both b and c? For illustration:
> Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}
> I keep thinking there must be a direct way to do this using Select or > some other function?
How can one infer from that list a list of its members that contain given elements, e.g. a list of members that contain b, or those that contain both b and c? For illustration:
Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}
I keep thinking there must be a direct way to do this using Select or some other function?
It's a good practice to use names that begin with a lower case letter, to avoid conflict with the names of built-in symbols and functions.
> How can one infer from that list a list of its members that contain > given elements, e.g. a list of members that contain b, or those that > contain both b and c? For illustration:
> Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}
> I keep thinking there must be a direct way to do this using Select or > some other function?
Select together with MemberQ will do the job. First, generate the subsets:
sets = Subsets[{a, b, c, d, e}, {3}]
This will select the ones that contain b:
Select[sets, MemberQ[#, b] &]
This will select the ones that contain both b and c:
It will find all sublists which contain *all* of the elements in <all> argument and *at least one* of the elements of <oneOf> argument (which can be omitted altogether). For example:
If the initial set is large, the above approach may turn inefficient due to a vary large number of elements in the initial list of subsets. You may want then to take the requirement of presence of certain elements into account already at the point when you generate the subsets.
> How can one infer from that list a list of its members that contain > given elements, e.g. a list of members that contain b, or those that > contain both b and c? For illustration:
> Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}
> I keep thinking there must be a direct way to do this using Select or > some other function?
On 11/7/09 at 6:47 AM, radford.scha...@mms.gov (r_poetic) wrote:
>First, generate a list of subsets using Subsets or KSubsets >functions. >Ns = KSubsets[{a,b,c,d,e},3] = {{a,b,c},{a,b,d},{a,b,e},{a,c,d}, >etc.} >How can one infer from that list a list of its members that contain >given elements, e.g. a list of members that contain b, or those that >contain both b and c? For illustration: >Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}} >I keep thinking there must be a direct way to do this using Select >or some other function?