IndexError: list index out of range when composing dict from 2 column csv
<p>My script that crunches numbers stored in csv gets the numbers into a dict from the csv like this:</p>

<pre><code>fide_rating_file = fide_csv_rating_file.read()
fide_rating_file = fide_rating_file.split("\n")
fide_rating_file2 = [f for f in fide_rating_file if len(f) &gt; 0]
fide_rating_file3 = [f.split(",") for f in fide_rating_file2]
fide_ratings = {f[0]: f[1] for f in fide_rating_file3}
</code></pre>

<p>This is probably not a pythonic way to work with csv (suggestions are welcome), I succesfully ran the script on tens of csv files. Now I am getting a traceback telling me that:</p>

<pre><code>File "...script.py", line 76, in script
fide_ratings = {f[0]: f[1] for f in fide_rating_file3}
File "...script.py", line 76, in &lt;dictcomp&gt;
fide_ratings = {f[0]: f[1] for f in fide_rating_file3}
IndexError: list index out of range
</code></pre>

<p>The csv looks like this (this is just an excerpt, is way too long to post here):</p>

<pre><code>1701991,2383
1407589,2188
1401815,2451
1411802,1913
1406248,2068
504599,2134
2252465,2099
</code></pre>

<p>The fact that it ran without errors on other files would suggest that this particular csv is corrupted. I checked for all inconsistencies I thought of compared to the rest of the files and found none. Thats why I am asking about the script here.</p>

<p>Per everyones advice I used the standard library csv module</p>

<pre><code>dict(csv.reader(fide_csv_rating_file))
</code></pre>

<p>Following error traceback pointed me to the incorrect lines, just removed them with regex find and replace and then succesfully created the dict.</p>

<p>Thanks guys.</p>

python