2016-03-04 105 views
-1
def every_second_line(report): 
    """ (Open File for reading) -> list of str 

    Return a list containing every second line (with leading and trailing 
    whitespace removed) in report, starting with the first line. 
    """ 
+4

你試過解決嗎? – vaultah

+2

歡迎來到StackOverflow。請閱讀並遵守幫助文檔中的發佈準則。 [最小,完整,可驗證的示例](http://stackoverflow.com/help/mcve)適用於此處。在您發佈代碼並準確描述問題之前,我們無法有效幫助您。 StackOverflow不是一個編碼或教程服務。 – Prune

+0

嘗試寫一些你希望能夠發揮作用的東西,然後(如果沒有),試着問爲什麼 – holdenweb

回答

0

如果我沒有記錯,你會做這樣的:

def every_second_line(report_location): 
    """ This code will return every second line with trailing whitespace stripped.""" 
    report = open(report_location, rb+) 
    second_lines = [a.strip() for a in report.readlines()[1::2]] 

    return second_lines 

我不跟我了Python的時刻,但這應該工作。祝你好運!