Skip to content

Add a line count - #7

Open
github-actions[bot] wants to merge 3 commits into
mainfrom
practice/line-count
Open

github-actions[bot] wants to merge 3 commits into
mainfrom
practice/line-count

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Adds line_count(text), with a test.

Closes #2.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. One thing to fix before it's merged: the issue says empty text should have no lines.

Comment thread src/tally/__init__.py

def line_count(text):
"""Return how many lines *text* holds."""
return len(text.split("\n"))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"".split("\n") gives [''], so empty text counts as one line. splitlines() handles that, and Windows line endings too:

Suggested change
return len(text.split("\n"))
if not text:
return 0
return len(text.splitlines())

Comment thread tests/test_tally.py

class LineCountTests(unittest.TestCase):
def test_counts_lines(self):
self.assertEqual(tally.line_count("one\ntwo"), 2)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for empty text as well?

@Community-Access Community-Access locked as resolved and limited conversation to collaborators Nov 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a line count to the summary

1 participant