Created
March 5, 2014 05:17
-
-
Save hpcx82/9361691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def look_and_say(member): | |
while True: | |
num = [] | |
count = [] | |
pre = None | |
for ele in member: | |
if len(num) > 0 and pre == ele: | |
count[len(count)-1] += 1 | |
else: | |
num += [ele] | |
count += [1] | |
pre = ele | |
member = ''.join([''.join([ str(i) for i in pair]) for pair in zip(count, num)]) | |
yield member |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个作为面试题到也不错~
可以考考思维,代码的组织,以及python的list,yield的运用:
for i in look_and_say('11'):
print i