Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.8K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Use output of the Position function to modify an expression?

Posted 6 years ago

Hello

In the following expression

 exp = HoldForm[#1^2 "+"] & /@ {4, 1, 7}

I want to remove the last "+". Its position I get with:

pos = Last[Position[exp, "+"]] 

I know it's correct because :

exp[[##]] &  @@  pos == "+"  (* True*)

But

exp[[##]] &  @@  pos = ""

will not work. I cannot understand it since

exp[[3, 1, 2]] = ""

works OK.

Please explain what is going on ? Thanks

POSTED BY: Jan Potocki
2 Replies
Posted 6 years ago

Yes ReplacePart does the job in a better way. But why Part won't work as I coded baffles me. Thanks.

POSTED BY: Jan Potocki
Posted 6 years ago

ReplacePart is probably a better way to do this

exp // ReplacePart[pos -> ""]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard