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 ...
106 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 ...
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, ...
2k 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?
3k 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 ...
764 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: ...
2k views

### Using ReplaceAll to replace a head

Why would this work to replace the head b with newHead: ...
640 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 ...
10k 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 :...
580 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 <...
217 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: ...
444 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 ...
256 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 ...