andioop to Programming HorrorEnglish · edit-22 years agoGod I wish there was an easier way to do thisimagemessage-square55linkfedilinkarrow-up1217arrow-down121
arrow-up1196arrow-down1imageGod I wish there was an easier way to do thisandioop to Programming HorrorEnglish · edit-22 years agomessage-square55linkfedilink
minus-squareSpeakinTelnetlinkfedilinkarrow-up15·edit-22 years agodef 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)
minus-squaresloppy_diffuser@sh.itjust.workslinkfedilinkEnglisharrow-up5·2 years agoPython added match/case?! Bunch of mypy issues have been closed too. Maybe its time to dust off some old projects.
minus-squareSpeakinTelnetlinkfedilinkarrow-up3·2 years agoIt was added in 3.10 and is surprisingly complete. The tutorial pep is a good starting point to see what it can accomplish
minus-squareAlyxMS [he/him]@hexbear.netlinkfedilinkEnglisharrow-up2·2 years agoWhat if the input is negative
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)
Python added match/case?! Bunch of mypy issues have been closed too. Maybe its time to dust off some old projects.
It was added in 3.10 and is surprisingly complete. The tutorial pep is a good starting point to see what it can accomplish
Well… At least it’s tail recursive.
What if the input is negative
Fixed!