說,我有以下的話,我想提出一個清單計數令牌和字符在名單
"cat,dog,fish" (first row)
"turtle,charzard,pikachu,lame" (second row)
"232.34,23.4,242.12%" (third row)
我的問題是我如何計算每行的標記,就像第一行有3個,第二排有4個,第三個有3個。之後我該如何計算字符數,然後爲每一行決定哪個記號具有最多字符?使輸出看起來像
token count = 3, character count = 10, fish has the most characters
token count = 4, character count = 25, charzard has the most characters
token count = 3, character count = 17, 242.12% has the most characters
只使用簡單的列表方法,如len()。並使用逗號作爲分隔符。謝謝,我真的失去了,因爲每次我嘗試使用帶剝離逗號(「」)我得到一個錯誤
我認爲你必須看看'split'方法 – shyam