Writing a list into the file by using Python
<p>I am trying to write a list into the file. I used:</p>

<pre><code>studentFile = open("students1.txt", "w")
for ele in studentList:
    studentFile.write(str(ele) + "\n")
studentFile.close()
</code></pre>

<p>As a result, the output was:</p>

<pre><code>['11609036', 'MIT', 'NE']

['11611262', 'MIT', 'MD']

['11613498', 'BIS', 'SA']
</code></pre>

<p>instead of:</p>

<pre><code>11609036    MIT    NE

11611262    MIT    MD

11613498    BIS    SA
</code></pre>

<p>How can I fix it?</p>

<p>How does your <code>studentList</code> list look like? I suspect its a nested list and you need another loop to pick individual elements.</p>

<pre><code>studentList = [['11609036', 'MIT', 'NE'],
               ['11611262', 'MIT', 'MD'],
               ['11613498', 'BIS', 'SA']]

studentFile = open("students1.txt", "w")
for student in studentList:
    for ele in student:
        studentFile.write(str(ele) + "\t")
    studentFile.write("\n")
studentFile.close()
</code></pre>

python