1
$\begingroup$

picked up Mathematica (transitioning from Python) a couple of days ago so forgive me for the newbie question. I'm trying to create a function which takes in a list of numbers and returns a list of the permutations of the number formed by the concatenation of those numbers. To be more clear ->

foo({1,2,1}) would output {121, 112, 211}. This is how I've tried to implement it.

my_function[x_] := FromDigits /@ Permutations[x]

Thinking that as long as the user input was a list like {1,2,3} this would work just fine. It doesn't seem to, so then I tried

my_function[x_,y_,z_] := FromDigits /@ Permutations[{x,y,z}]

This also didn't work.

This isn't the first time I've had trouble getting function definitions to work. What is it about my function definitions in this case that is causing them not to work?

Also - I've gone through the fast introduction for Python programmers. Any other recommended newbie resources?

Thanks

$\endgroup$

closed as off-topic by Carl Lange, Bob Hanlon, m_goldberg, kirma, Alex Trounev May 22 at 22:27

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." – Carl Lange, Bob Hanlon, m_goldberg, kirma, Alex Trounev
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ You can't use underscore in identifiers in the way you are used to in python. See here for details. That Q/A you may find generally useful as well. For resources, I recommend this QA. $\endgroup$ – Leonid Shifrin May 21 at 20:12
  • $\begingroup$ Specifically, change my_function to function and it will work. $\endgroup$ – mikado May 21 at 20:23
  • $\begingroup$ Thank you to both of you for your answers. $\endgroup$ – Jordan Man May 21 at 20:35