Skip to main content

Timeline for Tips for golfing in Python

Current License: CC BY-SA 3.0

12 events
when toggle format what by license comment
Nov 21 at 15:29 comment added JBernardo @ShadowRanger You are 2 years too late: codegolf.stackexchange.com/a/195165/2212 :)
Nov 3 at 19:10 comment added ShadowRanger @JBernardo: Which, in Py3.5+ with PEP 448 can shorten further to '%c'*26%(*R(97,123),) (21 chars, lowercase only), '%c'*26%(*R(65,90),) (20 chars, uppercase only) or '%c'*26%(*R(97,123),*R(65,90)) (30 chars, lowercase followed by uppercase).
Aug 15 at 19:03 comment added Mr. Lance E Sloan @KevinS, correct. With Python 3, it's now import string;string.ascii_lowercase, though.
Dec 21, 2017 at 20:26 comment added JBernardo If you going to be unfair and use range as R, my version is shorter than your original one: '%c'*26%tuple(R(97,123)) (only 24 chars) if you spell range it is just as long as the alphabet -- uppercase version is shorter
Apr 13, 2017 at 12:39 history edited CommunityBot
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Dec 21, 2015 at 6:10 comment added quintopia @TimPederick using 256 saves having to look up or remember what ord('z') is ;-) Also, I've learned that import string;string.ascii_letters is actually shorter if you don't mind the lowercase coming before the uppercase letters.
Dec 21, 2015 at 5:36 comment added Tim Pederick @quintopia: Why 256 instead of 122 (ord('z'))? Aside from it being the same length... Also, if you need alphanumerics, replace str.isalpha in @quintopia's version with str.isalnum. (But if you only need one case, the whole 36-character string is no longer than filter(str.isalnum,map(chr,range(90))).)
Nov 18, 2015 at 3:40 comment added quintopia if you need both cases, the shortest way I know is filter(str.isalpha,map(chr,range(256))). It's just barely shorter than s=map(chr,range(256));s+=map(str.lower,s)
Feb 20, 2015 at 2:35 history wiki removed Doorknob
Aug 13, 2014 at 19:20 comment added Kevin S In actual coding, use string.lowercase -- that's what it's there for.
Jun 7, 2014 at 19:53 comment added ToonAlfrink Might use this in actual coding, I feel so stupid when hardcoding these things :')
Apr 14, 2014 at 14:54 history answered undergroundmonorail CC BY-SA 3.0