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 is the mean absolute deviation of this data set of 82,84,84,87,88,90,90,92
How does the DNA help the World Wide Web scale so that billions of users can access billions of web pages
Help pls, it's due on Friday!! you'll get 13 points.
Because it determines which decisions are implemented, the ________ of the DSS is arguably its most important component.
Terry can ride 50 miles in 5 hours, what is his speed? In mph
150 find the value of x
Write an equation for a line perpendicular to Y=-4x-4 and passes through the points(12,5)
Write a short poem, in the style of your choosing, based on a book, story, or movie that you know well.
WILL CHOOSE BRAINLIEST, FIGURE OUT THE COMBINATION!!!!
Invoking time.time() returns the elapsed time in seconds since midnight of January 1, 1970. Write a function that returns the current time as a string. Call the