0

For loop for array to exchange elements of array?

10th Nov 2016, 8:19 PM
Mohamed Atef
Mohamed Atef - avatar
3 Answers
+ 1
A hint (I have to go offline for a little while). This works in Python: a,b = 1,2 (assigns both at once) so does this: myList[i],myList[j] = myList[j],myList[i] for swapping in place without a temporary variable.
10th Nov 2016, 9:22 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
It's not a loop Kirk Maybe Atef can add some words in question. What do you mean about exchange here?
1st Dec 2016, 6:26 PM
Luqman Raharjo
Luqman Raharjo - avatar
+ 1
Wish I could get a list of threads I was following. It wasn't supposed to provide the answer, since the structure of the array isn't specified. I might have just said "show the array" but I felt a quick boost was more helpful. The exchange shown should actually make the resulting loop less complex. Trouble with that should have (I hoped) resulted in more detail as you've asked.
1st Dec 2016, 6:41 PM
Kirk Schafer
Kirk Schafer - avatar