Omaxwellok Omaxwellok
  • 15-04-2020
  • Computers and Technology
contestada

Write a program that Read first n lines of file

Respuesta :

starmagpro
starmagpro starmagpro
  • 15-04-2020

Answer:

Python 2:

with open("datafile") as myfile:

   head = [next(myfile) for x in xrange(N)]

print head

Python 3:

with open("datafile") as myfile:

   head = [next(myfile) for x in range(N)]

print(head)

Both Python 2 & 3:

from itertools import islice

with open("datafile") as myfile:

   head = list(islice(myfile, N))

print head

Answer Link

Otras preguntas

What role did Louis Riel have in the Northwest rebellion?
Choose the point-slope form of the equation below that represents the line that passes through the point (−1, 6) and has a slope of −3. A.y − 6 = −3x − 3 B.y −
you are eighth in line to swinng at the playground. if every person ahead of you swings for 5 minutes, how long will you wait to swing?
Find greatest common monomial factor of the terms of the polynomial. 8x3y2 – 12x2y3 + 20x2y2 A. 16xy B. 4xy C. 8x2y2 D. 4x2y2
use a word dogged in an EASY sentence ;) dogged = stubbornly pursuading a goal hurrry up plz
Which words in the sentence are the complete noun clause? On this special night, dinner will be whatever you’d like. A. whatever you'd like B. dinner will be C.
−4x + 15= -13 what is x?
−4x + 15= -13 what is x?
what is 1/4 of 24= to
Select one of the factors of 5x2 + 7x + 2. a. (5x − 2) b. (x + 2) c. (5x + 1) d. None of the above