Re: [問題] word count in files

看板Python作者 (ccc)時間17年前 (2008/02/25 06:37), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串2/3 (看更多)
※ 引述《azulazure (獨在異鄉為異客)》之銘言: (deleted) : I tried to use range function to do the work, but it didn't work. : I wrote like this (following what I had above): : for x in range(wordcount): : if x in range(wordcount - 1) == False: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 此行有誤 可改成: if (x in range(wordcount - 1) == False: 或是: if x not in range(wordcount - 1): : print x : When I ran it, nothing happened. Can anyone tell me what's wrong? : Or is there a better way to do it? : My logic is that if the number is larger than the max number -1, : it should be the largest number. : Thanks in advance for any help! 何不直接印出max number (print wordcount) ? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.207.64

02/25 06:46, , 1F
when I use "print max(wordcount)", it gives an error
02/25 06:46, 1F

02/25 06:47, , 2F
says 'int' object is not iterable
02/25 06:47, 2F

02/25 06:48, , 3F
and I still have problem how to print the file name
02/25 06:48, 3F

02/25 06:48, , 4F
not just the number
02/25 06:48, 4F
文章代碼(AID): #17mV6pVt (Python)
討論串 (同標題文章)
文章代碼(AID): #17mV6pVt (Python)