Skip to content

Instantly share code, notes, and snippets.

@baiyanhuang
Created March 5, 2014 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baiyanhuang/9361691 to your computer and use it in GitHub Desktop.
Save baiyanhuang/9361691 to your computer and use it in GitHub Desktop.
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
@baiyanhuang
Copy link
Author

这个作为面试题到也不错~
可以考考思维,代码的组织,以及python的list,yield的运用:

for i in look_and_say('11'):
print i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment