開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の7章(プロのようにデータを操る)、7.3(復習問題)7、8、9、10、11.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3 print('7-7') mammoth = '''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.''' print('7-8') import re print(re.findall(r'\bc\w*\b', mammoth)) print('7-9') print(re.findall(r'\bc\w{3}\b', mammoth)) print('7-10') print(re.findall(r'\b\w*r\b', mammoth)) print('7-11') print(re.findall(r'\b\w*[aeiou]{3}\w*\b', mammoth))
入出力結果(Terminal, Jupyter(IPython))
$ ./sample3.py 7-7 7-8 ['cheese', 'city', 'cheese', 'cheek', 'could', 'cheese', 'cast', 'crush'] 7-9 ['city', 'cast'] 7-10 ['your', 'fair', 'Or', 'scar', 'Mr', 'far', 'For', 'your', 'or'] 7-11 ['queen', 'quietly', 'beau', 'queen', 'squeeze', 'queen'] $
0 コメント:
コメントを投稿