>< swap operator

Brian Oney brian.j.oney at googlemail.com
Tue Aug 14 11:07:37 EDT 2018


On Tue, 2018-08-14 at 10:55 -0400, Dennis Lee Bieber wrote:
> On Tue, 14 Aug 2018 06:18:41 -0700 (PDT), skybuck2000 at hotmail.com declaimed
> the following:
> 
> > On Monday, August 13, 2018 at 10:01:37 PM UTC+2, Léo El Amri wrote:
> > > On 13/08/2018 21:54, skybuck2000 at hotmail.com wrote:
> > > > I just had a funny idea how to implement a swap operator for types:
> > > > 
> > > > A >< B
> > > > 
> > > > would mean swap A and B.
> > > 
> > > I think that:
> > > 
> > > a, b = b, a
> > > 
> > > is pretty enough
> > 
> > LOL.
> > 
> > A >< B is shorter !
> > 
> 
> 	But is specific to swapping just two entities...
> 
> 	c, a, b = a, b, c
> 
> moves three entities at once -- and can be expanded for more.
> 
> > > > a = 1
> > > > b = 2
> > > > c = "confusion"
> > > > 
> > > > c, a, b = a, b, c
> > > > print a
> 
> 2
> > > > print b
> 
> confusion
> > > > print c
> 
> 1
Indeed, that is elegant.  It doesn't take a special knowledge of syntax, for good guessers. It also doesn't look like two male variables peeing on each others feet.


More information about the Python-list mailing list