0

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

30th Jul 2021, 5:44 PM
blackfish
blackfish - avatar
6 Respuestas
+ 4
a, b, c=c, b, a does your job!
30th Jul 2021, 6:13 PM
Ratnapal Shende
Ratnapal Shende - avatar
0
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?
30th Jul 2021, 6:41 PM
blackfish
blackfish - avatar
0
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...
30th Jul 2021, 6:46 PM
blackfish
blackfish - avatar
0
✩✮★✮✩ Would you mind to look at the code again from 37 line? Will that work as I think?
30th Jul 2021, 7:43 PM
blackfish
blackfish - avatar
0
✩✮★✮✩ Thanks a lot! I hope it will work. No possibility to check it now... Windows update on my machine 😱
30th Jul 2021, 8:18 PM
blackfish
blackfish - avatar