MathGroup Archive 2005

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

Search the Archive

Re: simple set operations


Edward Peschko wrote:
> hey all,
> 
> I'm hesitant to ask these questions (because they are so simple) but after a 
> 15 minute search through the docs I'm getting nowhere, so here goes:
> 
>     1) what's the easiest way to generate a list of elements? ie:
> 
> 	'a' .. 'h' == { a,b,c,d,e,f,g,h }
> 
>     2) Is there a quick way to check whether an element is in a set?
> 
> 	if ('a' == (any('a','b','c','d')) { print "a is in a,b,c,d"; }
> 
> The first one I see could possibly be done by 'Array', but I don't see how -
> the '#' refers to the generation of numbers, but there seems to be no 
> corresponding 'letter' symbol.
> 
> 
> As for #2, the easiest way would be through an overloading of the '==' operator,
> but again, that doesn't seem to work..
> 
> Thanks much for any help,
> 
> Ed
> 

1) if you want to generate a list containing *symbols* with consecutive 
names (that is the way I understood the question), try this

In[1]:=
lst = ToExpression[CharacterRange["a", "h"]]

Out[1]=
{a, b, c, d, e, f, g, h}

If you just want a list of *numbers* you would go for

In[2]:=
lstnum = Range[8]

Out[2]=
{1, 2, 3, 4, 5, 6, 7, 8}

2) here we go:
In[111]:=
MemberQ[lst, a]

Out[111]=
True

I'm sure you'll figure out, how to use Print[] and If[] to achieve the 
wanted behaviour.

Torsten


  • Prev by Date: Problem with Hyperlinks
  • Next by Date: adding text to a plot erases plot?
  • Previous by thread: Re: simple set operations
  • Next by thread: Re: Re: Re: Re: Re: simple set operations