開発環境
- macOS Mojave - Apple
- Emacs (Text Editor)
- Python 3.7 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の7章(プロのようにデータを操る)、7.3(復習問題)7-7、8、9、10、11.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3 import re print('7.') with open('ODE ON THE MAMMOTH CHEESE.txt') as f: mammoth = f.read() print(mammoth) print('8.') for word in re.findall(r'\ba\w*\b', mammoth): print(word) print() print('9.') for word in re.findall(r'\bc\w{3}\b', mammoth): print(word) print() print('10.') for word in re.findall(r'\b\w*r\b', mammoth): print(word) print() print('11.') for word in re.findall(r'\b\w*[aeiou]{3}\w*\b', mammoth): print(word)
入出力結果(Terminal, Jupyter(IPython))
$ ./sample3.py 7. We have seen thee, queen of cheese, Lying quietly at your ease, Gently fanned by evening breeze, Thy fair form no flies dare seize. All gaily dressed soon you'll go To the great Provincial show, To be admired by many a beau In the city of Toronto. Cows numerous as a swarm of bees, Or as the leaves upon the trees, It did require to make thee please, And stand unrivalled, queen of cheese. May you not receive a scar as We have heard that Mr. Harris Intends to send you off as far as The great world's show at Paris. Of the youth beware of these, For some of them might rudely squeeze And bite your cheek, then songs or glees We could not sing, oh! queen of cheese. We'rt thou suspended from balloon, You'd cast a shade even at noon, Folks would think it was the moon About to fall and crush them soon. 8. at admired a as a as a as as as at a at and 9. city cast 10. your fair Or scar Mr far For your or 11. queen quietly beau queen squeeze queen $
0 コメント:
コメントを投稿