Skip to main content
Tweeted twitter.com/StackMma/status/1573235728967925762
Became Hot Network Question
changed variables to streamline the answering process
Source Link
Syed
  • 59.5k
  • 5
  • 40
  • 95

I'm a beginner for programming with Mathematica and have a simple question.

Suppose we have a list of lists, for example,

lalist = {{1,3}, {2,3}, {4}}

I want to gather the lists if they have a common element. For example,

{{1,2,3}, {4}}

Another nontrivial example would be

lblist = {{1}, {1,4}, {2,3}, {5,6}, {2,4}}
(*{{1,2,3,4}, {5,6}}*)

Length of each list is less than 2. Thanks.

I'm a beginner for programming with Mathematica and have a simple question.

Suppose we have a list of lists, for example,

l = {{1,3}, {2,3}, {4}}

I want to gather the lists if they have a common element. For example,

{{1,2,3}, {4}}

Another nontrivial example would be

l = {{1}, {1,4}, {2,3}, {5,6}, {2,4}}
(*{{1,2,3,4}, {5,6}}*)

Length of each list is less than 2. Thanks.

I'm a beginner for programming with Mathematica and have a simple question.

Suppose we have a list of lists, for example,

alist = {{1,3}, {2,3}, {4}}

I want to gather the lists if they have a common element. For example,

{{1,2,3}, {4}}

Another nontrivial example would be

blist = {{1}, {1,4}, {2,3}, {5,6}, {2,4}}
(*{{1,2,3,4}, {5,6}}*)

Length of each list is less than 2. Thanks.

Source Link

Join and Union nested lists if they intersect

I'm a beginner for programming with Mathematica and have a simple question.

Suppose we have a list of lists, for example,

l = {{1,3}, {2,3}, {4}}

I want to gather the lists if they have a common element. For example,

{{1,2,3}, {4}}

Another nontrivial example would be

l = {{1}, {1,4}, {2,3}, {5,6}, {2,4}}
(*{{1,2,3,4}, {5,6}}*)

Length of each list is less than 2. Thanks.