甲Char_Record
是3項列表[char, total, pos_list]
其中找到元素的索引occurence的字符串數
char
是一個字符串total
位於NAT較char
出現的次數
pos_list
是NAT的代表char
使用函數build_char_records()
應產生一個排序列表,其中每個字符都代表(小寫)。
例如:
>>>build_char_records('Hi there bye')
['',2,[2,8]]
['b',1,[9]]
['e',3,[5,7,11]]
['h',2[0,4]]
['i',1,[1]]
['r',1,[6]]
['t',1,[3]]
['y',1,[10]]
我只是寫了這個樣子,我不知道該怎麼做,有人幫助,請。謝謝。
def build_char_records(s):
s=sorted(s)
a=[]
for i in range(len(s)):
你也許可以爲每個字符做匹配次數的正則表達式。即「a」:'count = len(re.match(/ [a]/g,phrase).groups())? –