Group Abstract Group Abstract

Message Boards Message Boards

How to "Lower Triangularize" a list of ordered pairs?

GROUPS:

Suppose I have a list of mixed types and want to construct a list of ordered pairs from that list where the first element comes before the second element in the original list. I'm sure there's a better approach than what I've come up with:

In[15]:= lst = {0, "a", 2, "cd", 10};

In[16]:= Select[Flatten[Outer[List, lst, lst], 1],
Position[lst, #[[1]]][[1, 1]] < Position[lst, #[[2]]][[1, 1]] &]

Out[16]= {{0, "a"}, {0, 2}, {0, "cd"}, {0, 10}, {"a", 2}, {"a",
"cd"}, {"a", 10}, {2, "cd"}, {2, 10}, {"cd", 10}}
POSTED BY: Frank Kampas
Answer
3 months ago

Use Subsets[]:

In[8]:= Subsets[lst, {2}]
Out[8]= {{0, "a"}, {0, 2}, {0, "cd"}, {0, 10}, {"a", 2}, {"a", "cd"}, {"a", 10}, {2, "cd"}, {2, 10}, {"cd", 10}}
POSTED BY: Szabolcs Horvat
Answer
3 months ago

Thanks.

POSTED BY: Frank Kampas
Answer
3 months ago