Practical Programming
An Introduction to Computer Science
Using Python 3
(Pragmatic Programmers)
(Pragmatic Bookshelf)
Paul Gries (著) Jennifer Campbell (著)
Jason Montojo (著) Lynn Beighley (編集)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 8(Storing Collections of Data Using Lists)、8.9(Exercises) 4-a, b, c, d, e, f.を解いてみる。
8.9(Exercises) 4-a, b, c, d, e, f.
コード(BBEdit)
sample4.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
ids = [4353, 2314, 2956, 3382, 9362, 3900]
print(ids)
print('a.')
ids.remove(3382)
print(ids)
print('b.')
print(ids.index(9362))
print('c.')
ids.insert(ids.index(9362) + 1, 4499)
print(ids)
print('d.')
ids.extend([5566, 1830])
print(ids)
print('e.')
ids.reverse()
print(ids)
print('f.')
ids.sort()
print(ids)
入出力結果(Terminal, IPython)
$ ./sample4.py [4353, 2314, 2956, 3382, 9362, 3900] a. [4353, 2314, 2956, 9362, 3900] b. 3 c. [4353, 2314, 2956, 9362, 4499, 3900] d. [4353, 2314, 2956, 9362, 4499, 3900, 5566, 1830] e. [1830, 5566, 3900, 4499, 9362, 2956, 2314, 4353] f. [1830, 2314, 2956, 3900, 4353, 4499, 5566, 9362] $
0 コメント:
コメントを投稿