Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.2K Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Find left side of definitions?

How do I find the left side of the sets as the following example?

o = {3, 2};
g = {9};
z = {5, 7};
f = {8, 11};

I'd like the result to be:

enter image description here

I would like a code to do this even if I change or add more definitions to the sets list freely, for example adding two more sets or renaming some.

My attempt to accomplish this (although believe that must have a much easier way):

ClearAll["Global`*"]

o = {3, 2};
g = {9};
z = {5, 7};
f = {8, 11};

FromLetterNumber[
 Select[Flatten[
   Table[If[
     Length[Flatten[
        Take[Position[
          Table[If[
            FromDigits[
              Flatten[
               Take[Alphabet[] // ToExpression, {ii}]]] \[Element] 
             Reals, 1], {ii, 1, 26}], 1], {ii}]]] < 2, 
     Take[Position[
       Table[If[
         FromDigits[
           Flatten[
            Take[Alphabet[] // ToExpression, {ii}]]] \[Element] Reals,
          1], {ii, 1, 26}], 1], {ii}]], {ii, 1, 26}]], NumberQ]]

enter image description here

My achievement was partial, because the answer is not organized correctly in a way that I want (instead, it was in alphabetic sort). Is there any way to do that with a smarter code? Would someone please know how to help me?

Thanks.

POSTED BY: Claudio Chaib
3 Replies

This is shorter, but still not ordered in your preferred way.

o = {3, 2};
g = {9};
z = {5, 7};
f = {8, 11};

#[[Flatten@Position[Symbol /@ #, _List]]] &@Names[$Context <> "*"]

(* {"f", "g", "o", "z"} * )

POSTED BY: Tim Laska
POSTED BY: Claudio Chaib

You are welcome Claudio. I am glad that it worked out for you and is more general than I imagined.

POSTED BY: Tim Laska
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard