1
$\begingroup$

I have list of names like

listname=[data1, runner, day, weather]

The values within the list of names are also lists themselves (numbers and names). like

data1=[38,40,5,16,52]

day=[Sunday, Monday]

Which command is used to edit the internal list using the external list?

like use listname to change values inside data1?

I add parts of the code what is the result:

input

validFN
validFN[[1, 3]]
ratio1hive1bee1repeat1[[3]]

output

{"ratio1hive1bee1repeat1", "ratio1hive1bee1repeat2","ratio1hive1bee1repeat3"}
{"ratio1hive1bee1repeat1", "ratio1hive1bee1repeat2","ratio1hive1bee1repeat3"}[[1, 3]]
{"00:00:00.220", -1, -3, -0.059234, -0.118468, 243, 0.132451,0.252855, 1.26427, "center"}

I'm really not an expert, with very little programming knowledge at all.

I think the names in the list validFN are only names, and the code does not recognize that there is a list with the same name defined earlier. Of course there is a high probability that I also make a mistake in semantics

$\endgroup$
3
  • $\begingroup$ Are these python lists? $\endgroup$
    – Syed
    Apr 2, 2022 at 16:31
  • $\begingroup$ No, The lists I have used here are just examples. one of them are CSV list that I import to the notebook and the others I built in Mathematica $\endgroup$
    – erez
    Apr 2, 2022 at 16:49
  • $\begingroup$ @erez, what Syed probably meant is, the examples you gave are not in correct Mathematica syntax. Lists in Mathematica are enclosed in curly braces ({ ... }). Can you show the exact code you are using in Mathematica ? Edit your question to include it by using the edit link under the question. $\endgroup$
    – MarcoB
    Apr 2, 2022 at 17:43

1 Answer 1

1
$\begingroup$

If we have this situation:

data1 = {38, 40, 5, 16, 52};
day = {Sunday, Monday};
runner = "runner";
weather = "weather";
listname = {data1, runner, day, weather}
(* output:
   {{38, 40, 5, 16, 52}, "runner", {Sunday, Monday}, "weather"}*)

and you want the 5 to be changed to 999, you could do this:

listname[[1, 3]] = 999

However, it's not clear that this is what you really want. This will change the value of listname, but it won't change the value of data1. Mathematica doesn't use references. If in addition to the above, you also do this:

data1[[4]] = 999

then listname remains as it was. Specifically, after all of these operations, you'll have

listname == {{38, 40, 999, 16, 52}, "runner", {Sunday, Monday}, "weather"}

and

data1 == {38, 40, 5, 999, 52}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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