看板 Python 關於我們 聯絡資訊
More pythontic way: import random times = 100 history = [random.choice(('head', 'tail')) for i in range(times)] for i in history: print i print 'head:', history.count('head') print 'tail:', history.count('tail') -- ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ - ██◤ ◥█◤ ██◣ ██◣ ██◤ ◢██ -▅▃ █ █ █ █▄▄ █ █ █ ◣ ◢ / - █ ██◢█ ▄▄▌ █ █ ◤ ◥ ◢█◣ █ ◣ ██◤ █ ██◤ ▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃ Mozilla Firefox -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.224.181
supencham:金害...有越來越看不懂的趨勢... 10/28 11:04
timerover:這樣寫漂亮很多 酷 10/29 09:57
timerover:我是寫c轉寫python的 xD 10/29 09:58
jtmh:大推 :) 10/29 14:15
Freak1033:但是這樣寫吃 linear space 喔. XD 11/01 06:10
jtmh:times 不大的前提下,我覺得程式看起來清楚比較重要耶!? 11/01 16:05
jtmh:不然這樣寫不僅記憶體吃得多,就連執行速度也比較慢啊 @@? 11/01 16:06