Swapped variables in a function in Python?
Hi, the below code is a part of Dynamo script (for Revit) with Python code. I had the code written for each operation separately, but would like to simplify it and use a function with variables (a, b, c). However, I have noticed that in one place variables are somethimes swapped (a with b). So, my question (I hope) is general and about Python, and you do neither have to know Dynamo nor Revit :-) Is it possible to use the same function (with something??? that's my question) or it has to be a separate function? Please look at the syntax of the code (it does not work on Sololearn) and any advice welcome! :-) https://code.sololearn.com/c8a1694A23a1
7/30/2021 5:44:56 PMblackfish
6 AnswersNew Answer
Check out this link I hope it helps you https://www.programiz.com/python-programming/examples/swap-variables
a, b, c=c, b, a does your job!
Thanks guys, but I'm not good in python, especially I function :-) That's why I always try to avoid them. Anyway... or my question was not precise or I do not understand your answers... I know that we can swap like this x,y=y,x but having a function with three variables def(a,b,c) you do not have access to the code of the function. You only can give as input three values/variables. So, how you swap 'a' with 'b' in one line of the code? Is it possible at all? Maybe not. That's my question/problem. Maybe it has to be the second function with the mentioned line different... Or maybe function in function will work here?
Just loudly thinking... maybe an extra fourth variable which let the function know when to swap the two variables? But no idea how it could work...
✩✮★✮✩ Would you mind to look at the code again from 37 line? Will that work as I think?
✩✮★✮✩ Thanks a lot! I hope it will work. No possibility to check it now... Windows update on my machine 😱