開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅲ.(Statements and Syntax)、Chapter 14.(Iterations and Comprehensions)、Test Your Knowledge: Quiz 3.を解いてみる。
その他参考書籍
- Pythonチュートリアル 第2版
- Python クックブック 第2版 (原書(最新版))
- Programming Python
- Python Pocket Reference (Pocket Reference (O'Reilly))
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 コメント:
コメントを投稿