this post was submitted on 12 Jun 2023
61 points (100.0% liked)

Programmer Humor

32581 readers
1074 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 7 points 1 year ago
a = a ^ b
b = a ^ b
a = a ^ b
[–] [email protected] 3 points 1 year ago

So you are asking the user to do it

[–] jnovinger 2 points 1 year ago (1 children)

I raise you

@lambda _: _()
def result() -> int:
    global a; global b; a, b = b, a

hat tip to @[email protected] via Cursed Python

[–] sisyphean 2 points 1 year ago* (last edited 1 year ago) (1 children)

Haha thanks, but the original idea is from @goodside on Twitter, I just screenshotted his tweet and harvested the upvotes :D

[–] jnovinger 2 points 1 year ago

D'oh, you're right! My bad and thanks for the catch!

[–] [email protected] 1 points 1 year ago (1 children)
[–] [email protected] 1 points 1 year ago

That's like the canonical "swap two pointers" trick