Star Trek Website
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
KHTangent@lemmy.world to Programmer Humor@lemmy.mlEnglish · 3 years ago

Swapping integers in Python

lemmy.world

message-square
7
link
fedilink
  • cross-posted to:
  • python@programming.dev
16

Swapping integers in Python

lemmy.world

KHTangent@lemmy.world to Programmer Humor@lemmy.mlEnglish · 3 years ago
message-square
7
link
fedilink
  • cross-posted to:
  • python@programming.dev
alert-triangle
You must log in or # to comment.
  • Jason Novinger@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 years ago

    I raise you

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

    hat tip to @sisyphean@programming.dev via Cursed Python

    • 𝕊𝕚𝕤𝕪𝕡𝕙𝕖𝕒𝕟@programming.dev
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 years ago

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

      • Jason Novinger@programming.dev
        link
        fedilink
        English
        arrow-up
        2
        ·
        3 years ago

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

  • abclop99@beehaw.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 years ago
    a = a ^ b
    b = a ^ b
    a = a ^ b
    
  • pec@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    0
    ·
    3 years ago

    Storing the value in the user instead of RAM!

    • softhat@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 years ago

      This actually raises a very good question - could you increase the amount of available RAM by using the user?

      Juggling chainsaws comes to mind.

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml

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

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 10 users / day
  • 781 users / week
  • 1.56K users / month
  • 5.09K users / 6 months
  • 124 local subscribers
  • 42.4K subscribers
  • 2.02K Posts
  • 40.4K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.mldeleted by creator
  • cat_programmer@lemmy.ml
  • BE: 0.19.18
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org