dimanche 28 juin 2015

Most efficient way of writing a list (of lists of lists) to a file in Python?

Given (pseudocode):

for city in cities:
  for info in city:
      #add some stuff to a list
   #add each list to a list (creating a list of lists)

  with open('file.csv', 'ab') as csvfile:
      writer = csv.writer(csvfile)
      writer.writerows(the list of lists) #in order of list

So I'm opening the file for each city and appending each list of each list-of-lists. What's a more efficient (quicker) way of achieving this?

Aucun commentaire:

Enregistrer un commentaire