開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 2.(List Data: Working with Ordered Data)、Reviewing Our Experiments の SHARPEN YOUR PENCIL(No. 1567) を取り組んでみる。
SHARPEN YOUR PENCIL(No. 1567)
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
phrase = "Don't panic!"
plist = list(phrase)
print(phrase)
print(plist)
for _ in range(4):
plist.pop()
plist.pop(0)
plist.remove("'")
plist.extend([plist.pop(), plist.pop()])
plist.insert(2, plist.pop(3))
new_phrase = ''.join(plist)
print(plist)
print(new_phrase)
入出力結果(Terminal, IPython)
$ ./sample1.py Don't panic! ['D', 'o', 'n', "'", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!'] ['o', 'n', ' ', 't', 'a', 'p'] on tap $
0 コメント:
コメントを投稿