Linked Questions

23
votes
0answers
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 ...
0
votes
1answer
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 ...
31
votes
5answers
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, ...
13
votes
7answers
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?
20
votes
2answers
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 ...
8
votes
4answers
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: ...
5
votes
2answers
2k views

Using ReplaceAll to replace a head

Why would this work to replace the head b with newHead: ...
7
votes
4answers
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 ...
3
votes
2answers
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 :...
9
votes
4answers
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 <...
8
votes
3answers
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: ...
7
votes
3answers
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 ...
10
votes
2answers
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 ...
5
votes
3answers
126 views

Create pattern to “redo” Nest for symbolic purposes, e.g. for commutators

I am symbolically working with matrix commutators (comm) and face the following issue: There are nested commutators in my final results, defined as ...
1
vote
0answers
5k views

How to remove brackets from this list? [closed]

I have some lists which have many brackets. I'd like to remove brackets from the lists. For example, I need to change the list ...

15 30 50 per page