How can I use a sublist in place the full list in a computation, but refer to it by the name of the full list.

I have a list

allData={{a, b, c}, {a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}};

For a particular evaluation I would like to get rid of the last 2 parts to get

allData = {{a, b, c}, {a1, b1, c1}};

But for a different evaluation I want to keep everything.

So is there a way how to quickly uncomment Delete or replace the part specification with... nothing?


returns, obviously,

Delete[{{a, b, c}, {a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}}]

Of course, in reality Delete is just one of many functions applied to allData.


closed as off-topic by MarcoB, Daniel Lichtblau, Henrik Schumacher, Alex Trounev, Carl Lange Apr 4 at 17:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Daniel Lichtblau, Henrik Schumacher, Alex Trounev, Carl Lange
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    $\begingroup$ Use an empty list. $\endgroup$ – J. M. is away Apr 3 at 13:26
  • $\begingroup$ Are you aware of the keyboard shortcut for commenting / uncommenting? You can select code and, on Windows, press Alt + / to toggle the comment status of your selection. $\endgroup$ – MarcoB Apr 3 at 13:37
  • $\begingroup$ @J.M.isslightlypensive Should I delete this question? Because your answer, obviously, works. Thank you. $\endgroup$ – Mefistofelis Apr 3 at 13:37
  • 1
    $\begingroup$ Probably I did not understand you right, but what I get from your question is a feeling that you are afraid to spoil the list allData, right? If yes, nothing forces you to change the allData list. Why do not you create a new list like allDataNew=Take[allData,2]? $\endgroup$ – Alexei Boulbitch Apr 3 at 13:39
  • $\begingroup$ @MarcoB or left click + u. Yes, I am aware of that. The embarrassing problem was that I had no clue how 'empty list' would work. $\endgroup$ – Mefistofelis Apr 3 at 13:40

I would not fool around with Delete or commenting or uncommenting. Instead I would enclose the particular computation that needs only the 1st two elements in Block.


data = {{a, b, c}, {a1, b1, c1}, {a2, b2, c2} ,{a3, b3, c3}};
Block[{data = data[[;; 2]]}, data^2]

{{a^2, b^2, c^2}, {a1^2, b1^2, c1^2}}

But data is unchanged.


{{a, b, c}, {a1, b1, c1}, {a2, b2, c2} ,{a3, b3, c3}};


Not the answer you're looking for? Browse other questions tagged or ask your own question.