Linked Questions

4 votes
1 answer
716 views

Removing Outer Brackets [duplicate]

I am getting this: {{{{{{1, 1}}, {2, 4}}, {3, 9}}, {4, 16}}, {5, 25}} I want it like this: {{1, 1}, {2, 4}, {3, 9}, {4, 16}, {5, 25}} so that I can use this as coordinate points in ListPlot to ...
Lost's user avatar
  • 226
23 votes
0 answers
1k views

Strip waste braces in nested list [duplicate]

I have nested lists wherein there are a lot of waste levels which looks like l = {{{{{{2, 2}}, 3}, 2, {{2, 33}}, 4, 5}}}; I would like to reduce it to somthing ...
Филипп Цветков's user avatar
0 votes
1 answer
131 views

How to take single item out of List? [duplicate]

I often get Lists that contain a single item, like {name} or {{2,3,4}}. Is there a function ...
Aron's user avatar
  • 1,732
33 votes
5 answers
2k views

How to perform a depth-first preorder traversal of an expression?

Mathematica provides functions that perform a depth-first postorder traversal, or which use such a traversal, including: Scan, ...
Mr.Wizard's user avatar
  • 272k
17 votes
7 answers
3k views

How to Flatten {1, {2, {3, 4}, 5}, 6} into {1, {2, 3, 4, 5}, 6}?

I've tried 3 methods but all failed to do that. 1st Method Apply[Flatten, {1, {2, {3, 4}, 5}, 6}, {2}] 2nd Method ...
kile's user avatar
  • 1,671
13 votes
7 answers
3k views

Brackets around each item in matrix

I have a matrix where every item in the matrix has its own brackets that I do not want. How can I remove the brackets around each item?
C. Tamaro's user avatar
  • 131
24 votes
2 answers
5k views

Determine whether some expression contains a given symbol

Given a symbol t and an expression expr, how can I determine whether or not the symbol t ...
Ian Hincks's user avatar
  • 1,859
9 votes
4 answers
1k views

Delete efficiently rows of empty list elements inside a list

What is the most efficient method for deleting a row of empty list elements? For example, here is a list with one row of empty list elements: ...
awyr_agored's user avatar
7 votes
2 answers
3k views

Using ReplaceAll to replace a head

Why would this work to replace the head b with newHead: ...
seismatica's user avatar
  • 5,101
7 votes
5 answers
944 views

How to Apply Functions to Lists with Many Curly Brackets?

For example, consider the list defined below. samplelist = {{{1,2,3,4}}, {{5,6,7,8}}}; How would I apply the Times operator ...
user155812's user avatar
3 votes
2 answers
21k views

Is there a function in Mathematica which removes brackets wrapping an expression?

Is there a function in Mathematica which removes brackets from an expression? RemoveBrackets[ {3} ] 3 Note: inspired by @garej's answer to this question :...
Conor's user avatar
  • 7,449
9 votes
5 answers
285 views

Prevent testing Head with ReplaceAll

I have a list of strings list. I am trying to get rid of some elements that match string pattern patt: ...
amrods's user avatar
  • 637
9 votes
4 answers
685 views

What is shorthand way of Reap list that may be empty because of zero Sow

Sometimes because of conditionals, you cannot guarantee that Sow will be called at least once. Reap[Sow[1]][[2,1]] results in <...
Manuel --Moe-- G's user avatar
7 votes
3 answers
575 views

Obtaining the number of iterations used in ReplaceRepeated

ReplaceRepeated has an option MaxIterations which indicates Mathematica is keeping track of the number of iterations. Is there ...
PlaysDice's user avatar
  • 804
10 votes
2 answers
266 views

Unexpected behavior using `ReplaceAll[]` for nested lists [duplicate]

ReplaceAll[] might lead to unexpected behavior (at least it surprised me). I use ReplaceAll[] to convert a list (basically data ...
Dennis Guse's user avatar

15 30 50 per page