Message Boards Message Boards

0
|
3730 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Remove outer braces of nested list

Posted 3 years ago

Hello everyone,

A function is giving me a nested list of variable length, which I would like to use as argument for Intersection[list1, list2, ...] as a next step. But how can I get rid of those outer curly braces?

Intersection[] only accepts single lists as arguments, not one nested list. But I fail horribly at this very simple (?) task.

If the nested list had a fixed amount of elements, I could simply write

Intersection[%[[1]], %[[2]], ...]

But sometimes the nested list looks like this

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

and sometimes like this

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

How to get to the next step, without knowing in advance the length of the nested list? The goal is something like

Intersection[{1,2},{2,3,4},{2,4,6}]

Thanks a lot already!

Oliver

POSTED BY: Oliver Ruessing
3 Replies

Hello Bill, hello Mike,

thanks a lot, very helpful!

Have a good day, Oliver

POSTED BY: Oliver Ruessing
Posted 3 years ago

Try

Intersection@@{{1,2},{2,3,4},{2,4,6}}

or

Apply[Intersection,{{1,2},{2,3,4},{2,4,6}}]

which are the same thing

POSTED BY: Bill Nelson
Posted 3 years ago

Check out Sequence[].

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

Group Abstract Group Abstract