[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: List.Swap - or like in Python
[Thread Prev] | [Thread Next]
- Subject: Re: List.Swap - or like in Python
- From: Rolf-Werner Eilert <rwe-sse@xxxxxxxxxx>
- Date: Mon, 11 Mar 2024 12:05:29 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Am 11.03.24 um 11:08 schrieb Benoît Minisini:
Le 11/03/2024 à 09:44, Rolf-Werner Eilert a écrit :Just a question or an idea what could be useful.When I want to sort an arry for instance, I will frequently have to swap contents of two different array cells likearray[x] = array[x+1]and back. As the contents of array[x] is lost, I have to temporarily store one of the values likesKeep = array[x] array[x] = array[x+1] array[x+1] = sKeepThe other day I stumbled over this one in Python: you can swap variable contents by just setting several variable names with commas on each side of the "=". If we translate it to Gambas, it would come out toarray[x], array[x+1] = array[x+1], array[x] or more simple: a, b = b, a just swaps the contents of variables a and b.There could be a function array.Swap(x, x+1) for arrays. But it would be only useful for arrays. Python's idea is more versatile as it covers single variables as well. You can mix arrays with variables and even set in expressions (like array[x], b = b, array[x]+3).Could you imagine introducing such a thing for Gambas? Regards RolfYou can do in Gambas: Swap array[x], array[x + 1] But a dedicated array function array.Swap(x, x + 1) would be faster. Regards,
Oh - my goodness, there it is, and I haven't known about it :) Thanks so much! Regards Rolf
Re: List.Swap - or like in Python | Fabien Bodard <gambas.fr@xxxxxxxxx> |
List.Swap - or like in Python | Rolf-Werner Eilert <rwe-sse@xxxxxxxxxx> |
Re: List.Swap - or like in Python | Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> |