2016年8月3日 星期三

不用條件敘述判斷奇偶數(Judge a number is even or odd without selection statement)

判斷一整數是否為偶數,若為偶數則輸出1,若否則輸出0
input: 123
output: 0
input: -12
output: 1

直觀法可用if-else判斷:

2013年12月25日 星期三

多重分隔號字串切割之方法暨效能比較 ( Compare performance of string splitting with multiple delimiters )

在Python中,str內建split()函式(method)做字串分割用
strT = "a1,a2,a3"
strT.split(',')

#output => ['a1', 'a2', 'a3']
單個分隔符號可以使用split()
本文探討多個分隔符號(例如:"a1,a2;a3-a4#a5")情況下的字串分割方法並比較其效能:
目標:
input: "a1,a2;a3-a4#a5"
output: ["a1", "a2", "a3", "a4", "a5"]

2013年12月19日 星期四

更動dict內容的效能比較 ( Compare performance of dict updating )

字典(dict)是Python內建的資料型態物件(Built-in Types)
關於dict的宣告、使用方式等,有興趣的讀者請自行參考Python官方文件
網路上亦有許多資料,此不贅述

本文試圖比較兩種更動dict的方法的效能