開発環境
- macOS Mojave - Apple
- Emacs (Text Editor)
- Python 3.7 (プログラミング言語)
Head First Python 第2版 ―頭とからだで覚えるPythonの基本 (Paul Barry (著)、嶋田 健志 (監修)、木下 哲也 (翻訳)、オライリージャパン)の12章(高度なイテレーション - 猛烈にループする)、自分で考えてみよう(p. 497)を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
print('1.')
data = [1, 2, 3, 4, 5, 6, 7, 8]
events = [num for num in data if not num % 2]
print(events)
print('2.')
data = [1, 'one', 2, 'two', 3, 'three', 4, 'four']
words = [num for num in data if isinstance(num, str)]
print(words)
print('3.')
data = list('So long and thanks for all the fisn'.split())
title = [word.title() for word in data]
print(title)
入出力結果(Terminal, Jupyter(IPython))
$ ./sample2.py 1. [2, 4, 6, 8] 2. ['one', 'two', 'three', 'four'] 3. ['So', 'Long', 'And', 'Thanks', 'For', 'All', 'The', 'Fisn'] $
0 コメント:
コメントを投稿