programming.dev
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
andioop to Programming HorrorEnglish ·
edit-2
1 year ago

God I wish there was an easier way to do this

message-square
55
link
fedilink
195

God I wish there was an easier way to do this

andioop to Programming HorrorEnglish ·
edit-2
1 year ago
message-square
55
link
fedilink
  • SpeakinTelnet
    link
    fedilink
    arrow-up
    15
    ·
    edit-2
    1 year ago
    def is_even(n):
        match n:
            case 1:
                return False
            case 0:
                return True
            # fix No1
            case n < 0:
                return is_even(-1*n)
            case _:
                return is_even(n-2)
    
    • sloppy_diffuser@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      5
      ·
      1 year ago

      Python added match/case?! Bunch of mypy issues have been closed too. Maybe its time to dust off some old projects.

      • SpeakinTelnet
        link
        fedilink
        arrow-up
        3
        ·
        1 year ago

        It was added in 3.10 and is surprisingly complete. The tutorial pep is a good starting point to see what it can accomplish

    • Chobbes@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      Well… At least it’s tail recursive.

    • AlyxMS [he/him]@hexbear.net
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      What if the input is negative

      • SpeakinTelnet
        link
        fedilink
        arrow-up
        4
        ·
        1 year ago

        Fixed!

Programming Horror

programming_horror

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: [email protected]

Welcome to Programming Horror!

This is a place to share strange or terrible code you come across.

For more general memes about programming there’s also Programmer Humor.

Looking for mods. If youre interested in moderating the community feel free to dm @[email protected]

Rules

  • Keep content in english
  • No advertisements (this includes both code in advertisements and advertisement in posts)
  • No generated code (a person has to have made it)

Credits

  • Icon base made by Lorc under CC BY 3.0 with modifications to add a gradient
Visibility: Public
globe

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

  • 1 user / day
  • 1 user / week
  • 6 users / month
  • 114 users / 6 months
  • 759 local subscribers
  • 2.07K subscribers
  • 36 Posts
  • 296 Comments
  • Modlog
  • mods:
  • Vacant
  • BE: 0.19.11
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org