A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-April/023702.html below:

[Python-Dev] Use for enumerate

[Python-Dev] Use for enumerate [Python-Dev] Use for enumerateBen Wolfson wolfson@midway.uchicago.edu
Fri, 26 Apr 2002 22:21:55 -0500 (CDT)
(I'm not subscribed so this won't thread right, but oh well)

This doesn't preserve the same semantics as the original, in that it
always reads the entire file, but it is awfully short:

def getline(filename, lineno):
    return (lineno < 1 and ('',) or
            ([ln for (i,ln) in enumerate(open(filename)) if
             i==lineno-1] or ('',)))[0]


-- 
BTR    
YOU HEAR ME, BEN WOLFSON?!? YOUR SUPERCILIOUS CONTEMPT POWERS CANNOT
WITHSTAND THE POWER OF MY BOORISH *DIMWIT* *RAY*!!!!
  -- revjack





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4