I need algorithm for my task
Chris Angelico
rosuav at gmail.com
Wed Nov 5 23:14:05 EST 2014
More information about the Python-list mailing list
Wed Nov 5 23:14:05 EST 2014
- Previous message (by thread): I need algorithm for my task
- Next message (by thread): I need algorithm for my task
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Nov 6, 2014 at 3:00 PM, Denis McMahon <denismfmcmahon at gmail.com> wrote: > def baseword(s): > """find shortest sequence which repeats to generate s""" > return s[0:["".join([s[0:x]for k in range(int(len(s)/x)+1)])[0:len > (s)]for x in range(1,len(s)+1)].index(s)+1] That's hardly a PEP-8 compliant line, but I can help out a bit. return s[0:[(s[0:x]*(len(s)//x+1))[0:len(s)]for x in range(1,len(s)+1)].index(s)+1] That's still 83 characters without indentation, but it's close now. I love the algorithm. Took me a bit of analysis (and inspection of partial results) to understand what your code's doing, but it's stupidly elegant and elegantly stupid. ChrisA
- Previous message (by thread): I need algorithm for my task
- Next message (by thread): I need algorithm for my task
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list