collections分類
一個是不可變長度的
array (python中tuple)
string
List
Dictionary(or Associative Array)
C#的dictionary的key可以不是string類型
python和php(array) 中key都是string, python所以用hash實現了dictionary, php不知道
collections的操作
長度
遍歷(foreach, for)
foreach
每個遍歷對象是傳值,改變它不會影響原collection
遍歷時如果對collection添加或刪除元素, 遍歷就會出錯
for
正序遍歷時對collection修改也會出錯, 但逆序遍歷對collection刪除時就可以(但是一次只能刪除一個,因爲步長是1,這是最常見的, 像步長是>1, 或一次刪除>1個元素, 沒印象)
map, filter
排序
子序列
slice, python的collection[m:n]
可變長的collection的操作
添加刪除
List.Add() List.Remove()
python collection: append(), del, extend()
string的操作
split, join
匹配
一般用正則, 簡單的匹配自帶的會快