Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as:

x=<|"firstValue" -> True, "isFirstValueTrue" -> False|>

I want to change it to:

<|"firstValue" -> True, "isFirstValueTrue" -> True|>

So I wrote the function:

f[x_] := If[x[["firstValue"]], x[["isFirstValueTrue"]] = True, x[["isFirstValueTrue"]] = False]

I got an error, but based on this answer: http://stackoverflow.com/questions/12875913/setsetps-in-the-part-assignment-is-not-a-symbolhttps://stackoverflow.com/questions/12875913/setsetps-in-the-part-assignment-is-not-a-symbol I was to correct it by usingSetAttributes[f, HoldAll]

But let's say I want to do this to a list of associations:

    x={<|"firstValue" -> True, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> True, "isFirstValueTrue" -> True|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> True|>}

so I wrote

Map[f[#] &, x]

However, the "in the part assignment is not a symbol." error appears again and you can't SetAttributes[Map, HoldAll]. I realize I can make a copy of the list and make changes to that, but the actual list I'm working with is much larger so I do not want to do that. The third solution in the link above is able to be mapped, but it doesn't seem like you can replace in an association. Any suggestions?

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as:

x=<|"firstValue" -> True, "isFirstValueTrue" -> False|>

I want to change it to:

<|"firstValue" -> True, "isFirstValueTrue" -> True|>

So I wrote the function:

f[x_] := If[x[["firstValue"]], x[["isFirstValueTrue"]] = True, x[["isFirstValueTrue"]] = False]

I got an error, but based on this answer: http://stackoverflow.com/questions/12875913/setsetps-in-the-part-assignment-is-not-a-symbol I was to correct it by usingSetAttributes[f, HoldAll]

But let's say I want to do this to a list of associations:

    x={<|"firstValue" -> True, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> True, "isFirstValueTrue" -> True|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> True|>}

so I wrote

Map[f[#] &, x]

However, the "in the part assignment is not a symbol." error appears again and you can't SetAttributes[Map, HoldAll]. I realize I can make a copy of the list and make changes to that, but the actual list I'm working with is much larger so I do not want to do that. The third solution in the link above is able to be mapped, but it doesn't seem like you can replace in an association. Any suggestions?

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as:

x=<|"firstValue" -> True, "isFirstValueTrue" -> False|>

I want to change it to:

<|"firstValue" -> True, "isFirstValueTrue" -> True|>

So I wrote the function:

f[x_] := If[x[["firstValue"]], x[["isFirstValueTrue"]] = True, x[["isFirstValueTrue"]] = False]

I got an error, but based on this answer: https://stackoverflow.com/questions/12875913/setsetps-in-the-part-assignment-is-not-a-symbol I was to correct it by usingSetAttributes[f, HoldAll]

But let's say I want to do this to a list of associations:

    x={<|"firstValue" -> True, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> True, "isFirstValueTrue" -> True|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> True|>}

so I wrote

Map[f[#] &, x]

However, the "in the part assignment is not a symbol." error appears again and you can't SetAttributes[Map, HoldAll]. I realize I can make a copy of the list and make changes to that, but the actual list I'm working with is much larger so I do not want to do that. The third solution in the link above is able to be mapped, but it doesn't seem like you can replace in an association. Any suggestions?

edited tags
Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Tweeted twitter.com/#!/StackMma/status/500093617504268288
deleted 7 characters in body
Source Link
Jon F.
  • 645
  • 8
  • 8

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as:

x=<|"firstValue" -> True, "isFirstValueTrue" -> False|>

I want to change it to:

<|"firstValue" -> True, "isFirstValueTrue" -> True|>

So I wrote the function:

f[x_] := If[x[["firstValue"]], x[["isFirstValueTrue"]] = True, x[["isFirstValueTrue"]] = False]

I got an error, but based on this answer: http://stackoverflow.com/questions/12875913/setsetps-in-the-part-assignment-is-not-a-symbol I was to correct it by using:SetAttributes[f, HoldAll]

SetAttributes[f, HoldAll].

But let's say I want to do this to a list of associations:

    x={<|"firstValue" -> True, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> True, "isFirstValueTrue" -> True|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> True|>}

so I wrote:

Map[f[#] &, x]

However, the "in the part assignment is not a symbol." error appears again and you can't SetAttributes[Map, HoldAll]. I realize I can make a copy of the list and make changes to that, but the actual list I'm working with is much larger so I do not want to do that. The third solution in the link above is able to be mapped, but it doesn't seem like you can replace in an association. Any suggestions?

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as:

x=<|"firstValue" -> True, "isFirstValueTrue" -> False|>

I want to change it to:

<|"firstValue" -> True, "isFirstValueTrue" -> True|>

So I wrote the function:

f[x_] := If[x[["firstValue"]], x[["isFirstValueTrue"]] = True, x[["isFirstValueTrue"]] = False]

I got an error, but based on this answer: http://stackoverflow.com/questions/12875913/setsetps-in-the-part-assignment-is-not-a-symbol I was to correct it by using:

SetAttributes[f, HoldAll].

But let's say I want to do this to a list of associations:

    x={<|"firstValue" -> True, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> True, "isFirstValueTrue" -> True|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> True|>}

so I wrote:

Map[f[#] &, x]

However, the "in the part assignment is not a symbol." error appears again and you can't SetAttributes[Map, HoldAll]. I realize I can make a copy of the list and make changes to that, but the actual list I'm working with is much larger so I do not want to do that. The third solution in the link above is able to be mapped, but it doesn't seem like you can replace in an association. Any suggestions?

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as:

x=<|"firstValue" -> True, "isFirstValueTrue" -> False|>

I want to change it to:

<|"firstValue" -> True, "isFirstValueTrue" -> True|>

So I wrote the function:

f[x_] := If[x[["firstValue"]], x[["isFirstValueTrue"]] = True, x[["isFirstValueTrue"]] = False]

I got an error, but based on this answer: http://stackoverflow.com/questions/12875913/setsetps-in-the-part-assignment-is-not-a-symbol I was to correct it by usingSetAttributes[f, HoldAll]

But let's say I want to do this to a list of associations:

    x={<|"firstValue" -> True, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> True, "isFirstValueTrue" -> True|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> False|>,
     <|"firstValue" -> False, "isFirstValueTrue" -> True|>}

so I wrote

Map[f[#] &, x]

However, the "in the part assignment is not a symbol." error appears again and you can't SetAttributes[Map, HoldAll]. I realize I can make a copy of the list and make changes to that, but the actual list I'm working with is much larger so I do not want to do that. The third solution in the link above is able to be mapped, but it doesn't seem like you can replace in an association. Any suggestions?

Formatted code
Source Link
Michael E2
  • 244.8k
  • 18
  • 351
  • 774
Loading
Source Link
Jon F.
  • 645
  • 8
  • 8
Loading