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

HELP PLEASE!Please answer if you read or watched the "Boy in stripped pajamas" please.Question: If you could sum up the entire movie in ONE word what would it b
john lewis what is hes memorable quote
A magician has four playing cards in random order in his hand ( 3 4 5 and 6) Magician wishes them placed in ascending order from his left to his right. * To do
Choose the equation of the horizontal line that passes through the point (2,3) 1) x= 2 2) x=3 3) y=2 4) y=3
If you buy 3 books at $3.95 each, how much change will you get from $20?*Please Show Work*
Find the vertex of the graph y equal x to the power of 2 plus 6 x minus 5
using your knowledge of cross products how would you solve for x in the following pair of equivalent fraction 7 over x equals 2/4
the name of this famous opera is lohengrin what is the noun in this sentence
How do you find and explain the answer?
Can you get sum of 99 by using all numbers (0-9) and only one mathematical symbols ?