看板 Python 關於我們 聯絡資訊
I'm trying to write a command that print the largest file in the current working directory. I'm able to print all the files and their wordcount, but I don't know how to print just the largest one. Here's what I have: import os cwd = os.getcwd() for file in os.listdir(cwd): if os.path.isdir(file) == False: if file[0] != '.': word = open(file, 'r').read().split() wordcount = len(word) 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: 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! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 69.143.181.102