>< swap operator

Marko Rauhamaa marko at pacujo.net
Tue Aug 14 09:28:19 EDT 2018


skybuck2000 at hotmail.com:
> 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 !

Don't forget the

   (A >:< B)

operator:

   def fib(n):
       curr = prev = 1
       for _ in range(n):
           (curr >:< prev) += prev
       return curr

Obviously, we see immediately the need for the Pythonic improvement:

   def fib(n):
       curr = prev = 1
       for _ in range(n):
           curr >+=< prev
       return curr


Marko



More information about the Python-list mailing list