Skip to content

Instantly share code, notes, and snippets.

@nutszebra
Last active November 20, 2015 09:56
Show Gist options
  • Save nutszebra/bb1d2b8fbd03e2436ef5 to your computer and use it in GitHub Desktop.
Save nutszebra/bb1d2b8fbd03e2436ef5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Link: http://www.cl.ecei.tohoku.ac.jp/nlp100/
"""
Question 03:
03. 円周率
"Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics."
という文を単語に分解し,各単語の(アルファベットの)文字数を先頭から出現順に並べたリストを作成せよ.
"""
import re
sentence = "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics."
print("".join([re.sub(r"\w+", str(len(re.findall(r"\w+",word)[0])), word) for word in sentence.split()]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment