andioop@programming.dev to Programming Horror@programming.devEnglish · edit-21 year agoGod I wish there was an easier way to do thisprogramming.devimagemessage-square46fedilinkarrow-up1184
arrow-up1164imageGod I wish there was an easier way to do thisprogramming.devandioop@programming.dev to Programming Horror@programming.devEnglish · edit-21 year agomessage-square46fedilink
minus-squareSpeakinTelnet@programming.devlinkfedilinkarrow-up13·edit-21 year 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-up0·1 year agoPython added match/case?! Bunch of mypy issues have been closed too. Maybe its time to dust off some old projects.
minus-squareSpeakinTelnet@programming.devlinkfedilinkarrow-up1·1 year agoIt was added in 3.10 and is surprisingly complete. The tutorial pep is a good starting point to see what it can accomplish
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)
Well… At least it’s tail recursive.
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