Read Online
Download PDF
Additional resources
Revision history
Known typos/bugs
Report a bug
License terms
About the author
"node301_1.gif" "node301_2.gif" "node301_3.gif"     Simple uses of Part

If it is necessary to replace some element of the list with a known address with some new expression or value (say, symbol <a>), this can be done directly. Here are our lists:




Say, we now want to replace the element with the address {5} with <a>:



Now, let us now in our list <complextestlist> replace a random element in every sublist with <a>:




Notice that such modifications as described above are only possible if lists are stored in some variable (in C we would say, that it is an L-value). In particular, this input is a mistake:    




Essentially, in all the above examples the Part command ([[ ]] ) was used for modification of expressions.

Note also that the modification of lists with Part introduces side effect, since it is the original variable where the list is stored that is modified, not the copy of the list.

"node301_15.gif" "node301_16.gif" "node301_17.gif"

Created by Wolfram Mathematica 6.0  (05 February 2009) Valid XHTML 1.1!