Skip to content

Commit 6b64ba4

Browse files
committed
picnixz suggestion
1 parent 7189b51 commit 6b64ba4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Lib/csv.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,14 @@ def _guess_delimiter(self, data, delimiters):
386386
charFrequency[char][count] += 1
387387

388388
for char, counts in charFrequency.items():
389-
presentCount = sum(counts.values())
390-
zeroCount = num_lines - presentCount
391-
if zeroCount > 0:
392-
items = list(counts.items()) + [(0, zeroCount)]
393-
else:
394-
items = list(counts.items())
389+
items = list(counts.items())
390+
missed_lines = num_lines - sum(counts.values())
391+
if missed_lines:
392+
# charFrequency[char][0] can only be deduced now
393+
# as it cannot be obtained when parsing the lines.
394+
assert 0 not in counts.keys()
395+
# Store the number of lines 'char' was missing from.
396+
items.append((0, missed_lines))
395397
if len(items) == 1 and items[0][0] == 0:
396398
continue
397399
# get the mode of the frequencies

0 commit comments

Comments
 (0)