4
$\begingroup$

Given a list of tuples where one element is a set:

{{{}, "a"}, {{1}, "a"}, {{2}, "a"}, {{3}, "a"}, {{1, 2}, 
  "a"}, {{1, 3}, "a"}, {{2, 3}, "a"}, {{1, 2, 3}, "a"}}

Which is the function that decomposes the sets into new tuples, repeating the other element in the tuple, i.e.

{{{{}, "a"}}, {{{1}, "a"}}, {{{2}, "a"}}, {{{3}, "a"}}, {{{1}, 
   "a"}, {{2}, "a"}}, {{{1}, "a"}, {{3}, "a"}}}

?

$\endgroup$
6
$\begingroup$
lst = {{{}, "a"}, {{1}, "a"}, {{2}, "a"}, {{3}, "a"}, {{1, 2}, "a"}, 
   {{1, 3}, "a"}, {{2, 3}, "a"}, {{1, 2, 3}, "a"}}

Thread[{List /@ # /. {} -> {{}}, #2}] & @@@ lst // Column

enter image description here

Alternatively,

Tuples[{List /@ # /. {} -> {{}}, {#2}}] & @@@ lst

same result

$\endgroup$
5
$\begingroup$

I believe this is what you want:

expr /. {
   idxs_ : {__Integer},
   el_
   } :> ({{#}, el} & /@ idxs)

where expr is your expression.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.