Python 獲取檔案中最長行的長度和最長行
# Get the number of lonest line
f = open('nihao')
longestLine = max(len(line.strip()) for line in f)
f.close()
print longestLine
# Get the longest line
f = open('nihao')
allLines = [line.strip() for line in f]
f.close()
longest = 0
longLine = ""
for line in allLines:
linelen = len(line)
if linelen > longest:
longest = linelen
longLine = line
print 'Longest line: %s' % longLine
print 'The number of longest line: %s' % longest
相關文章
- PHP如何獲取最大檔名長度PHP
- C++獲取陣列的長度C++陣列
- c++多執行緒按行讀取同一個每行長度不規則檔案C++執行緒
- shell 怎麼獲取引數的長度
- c++ 獲取檔案建立時間、修改時間、訪問時間、檔案內容長度C++
- 按位長度進行字串的分割輸出,長度不足補0字串
- golang 計算最長不重複字串長度Golang字串
- 最長的Hello, World!(Python)Python
- c語言獲取陣列長度的函式C語言陣列函式
- 用 GetLength(int dimension) 獲取陣列指定維度的長度。陣列
- 獲取C/C++字串、字元陣列長度C++字串字元陣列
- [work] python讀取txt檔案最後一行Python
- Python原始檔一行字元過長造成的問題Python字元
- Python如何獲取當前執行檔案路徑?Python
- python獲取程式執行檔案路徑的方法其一Python
- 怎麼透過Python獲取檔案指定行的內容?Python
- python獲取影片時長並移動到對應時長的資料夾下Python
- 巧用PHP函式或常量快速獲取PHP版本號、最大檔名長度PHP函式
- LeetCode最長公共字首(Python)LeetCodePython
- MYSQL單行長度不能超過 65535MySql
- 讀取檔案最後一行
- 關於FileDownloader檔案長度校驗的問題
- pyav 如何獲取影片時長?
- 最長
- JS指定音訊audio在某個時間點進行播放,獲取當前音訊audio的長度,音訊時長格式轉化JS音訊
- 038、長幹行
- [譯] Javascript 中最長的關鍵字序列長什麼樣子?JavaScript
- 直播軟體原始碼,JS獲取指定長度的隨機字元原始碼JS隨機字元
- lc1771 由子序列構造的最長迴文串的長度
- 使用awk和sed獲取檔案奇偶數行的方法總結
- 字串最後一個單詞的長度字串
- 資料庫系列:字首索引和索引長度的取捨資料庫索引
- 【leetcode】32. Longest Valid Parentheses 最長的有效匹配括號子串長度LeetCode
- go 語言中的 rune,獲取字元長度Go字元
- 如何增長程式碼長度
- 設定Vim編輯器裡Tab的長度,行號
- python讀取檔案指定行的三種方法Python
- LeetCode133:給定一個字串,找出最長的不具有重複字元的子串的長度。例如,“abcabcbb”不具有重複字元的最長子串是“abc”,長度為3。對於“bbbbb”,最長的不具有重複字元的子串是LeetCode字串字元
- JavaScript獲取字串的長度區分漢字JavaScript字串