2017年8月23日水曜日

開発環境

Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 13.(Advanced Iteration: Looping Like Crazy)の SHARPEN YOUR PENCIL(No. 9296) を取り組んでみる。

SHARPEN YOUR PENCIL(No. 9296)

コード(Emacs)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

print('1.')

data = list(range(1, 9))

evens = [num for num in data if num % 2 == 0]

print(evens)

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 fish'.split())

title = [word.title() for word in data]

print(title)

入出力結果(Terminal, IPython)

$ ./sample2.py
1.
[2, 4, 6, 8]
2.
['one', 'two', 'three', 'four']
3.
['So', 'Long', 'And', 'Thanks', 'For', 'All', 'The', 'Fish']
$

0 コメント:

コメントを投稿