開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Python 3.5 (プログラミング言語)
Think Python (Allen B. Downey (著)、 O'Reilly Media)のChapter 9.(Case Study Word Play)のExercises 9-4(No. 1972)を取り組んでみる。
Exercises 9-4(No. 1972)
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def uses_only(word, letters):
for ch in word:
if ch not in letters:
return False
return True
def p(f, letters):
for line in f:
words = line.split()
for word in words:
if uses_only(word, letters):
print(word)
if __name__ == '__main__':
with open('words.txt') as f:
for letters in ['aeiou', 'aeiouy']:
print('letters: {0}'.format(letters))
p(f, letters)
f.seek(0)
入出力結果(Terminal, IPython)
./sample4.py letters: aeiou aa ae ai eau oe letters: aeiouy aa ae ai ay aye eau eye oe oy ya yay ye yea you $
0 コメント:
コメントを投稿