2014年10月6日月曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅲ.(Statements and Syntax)、Chapter 14.(Iterations and Comprehensions)、Test Your Knowledge: Quiz 3.を解いてみる。

その他参考書籍

Test Your Knowledge: Quiz 3.

コード(BBEdit)

sample3.py

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

print('for loop')
l = []
for x in range(10):
    l.append(x)
I = iter(l)
print(I.__next__())
print(I.__next__())

print('list comprehension')
l = [x for x in range(10)]
I = iter(l)
print(I.__next__())
print(I.__next__())

print('map (built-in function)')
l = map(lambda x: x, range(10))
print(l.__next__())
print(l.__next__())

print('sorted (built-in function)')
l = sorted(range(10))
I = iter(l)
print(I.__next__())
print(I.__next__())

入出力結果(Terminal, IPython)

$ ./sample3.py
for loop
0
1
list comprehension
0
1
map (built-in function)
0
1
sorted (built-in function)
0
1
$

0 コメント:

コメントを投稿