Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:57:42+00:00 2026-05-26T17:57:42+00:00

import csv a=[] with open(‘large.csv’,’w’) as f1: writer=csv.writer(f1, delimiter=’\t’,lineterminator=’\n’,) for i in range(1000000): for

  • 0
import csv
a=[]
with open('large.csv','w') as f1:
    writer=csv.writer(f1, delimiter='\t',lineterminator='\n',)

    for i in range(1000000):
        for j in range(i+1):
            a.append(i+j*0.2)
            #print i,j,a
        #want to write into same csv file???
        '''like            
               0     1     2......999999
            0  0.0
            1  1.0  1.2
            2  2.0  2.2   2.4
            .   .....
            .   .....
            999999
        ''' 
        a=[]

I have done this to avoid same caculation twice and as the list ‘a’ will grow large I have to initialize it again(after one iteration of the outer loop) .So, I want the list(before get initialized again) written into csv file in the above manner but I am not able to do so……please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:57:43+00:00Added an answer on May 26, 2026 at 5:57 pm

    Do you want to do something like this?

    import csv
    with open('large.csv','w') as f1:
        writer=csv.writer(f1, delimiter='\t',lineterminator='\n',)
        for i in range(1000000):
            row = [i + j*0.2 for j in range(i+1)]
            writer.writerow(row)
    

    or also with the row/column headers:

    import csv
    with open('large.csv','w') as f1:
        writer=csv.writer(f1, delimiter='\t',lineterminator='\n',)
        writer.writerow([''] + range(1000000))
        for i in range(1000000):
            row = [i] + [i + j*0.2 for j in range(i+1)]
            writer.writerow(row)
    

    The latter returns the following file (I have replaced 1000000 with 10):

            0       1       2       3       4       5       6       7       8       9
    0       0.0
    1       1.0     1.2
    2       2.0     2.2     2.4
    3       3.0     3.2     3.4     3.6
    4       4.0     4.2     4.4     4.6     4.8
    5       5.0     5.2     5.4     5.6     5.8     6.0
    6       6.0     6.2     6.4     6.6     6.8     7.0     7.2
    7       7.0     7.2     7.4     7.6     7.8     8.0     8.2     8.4
    8       8.0     8.2     8.4     8.6     8.8     9.0     9.2     9.4     9.6
    9       9.0     9.2     9.4     9.6     9.8     10.0    10.2    10.4    10.6    10.8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import csv with open('test.csv', 'w') as outfile: writer = csv.writer(outfile, delimiter=',', quoting=csv.QUOTE_MINIMAL) writer.writerow(['hi', 'dude'])
According to the its documentation csv.writer should use '\r\n' as lineterminator by default. import
Im using the following in Python2.x ; import csv f = open('test.csv', 'wb') writer
import csv from geopy import geocoders g = geocoders.Google() spamReader = csv.reader(open('locations.csv', 'rb'), delimiter='\t',
Possible Duplicate: Open a file in the proper encoding automatically my code: import csv
In the program I am writing, I want to be able to import CSV
import csv with open('thefile.csv', 'rb') as f: data = list(csv.reader(f)) import collections counter =
import csv with open('thefile.csv', 'rb') as f: data = list(csv.reader(f)) import collections counter =
import csv with open('test.csv', 'rb') as f: data = list(csv.reader(f)) import collections counter =
i am opening a csv file like this: import csv reader = csv.reader(open(book1.csv, rb))

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.