-
Notifications
You must be signed in to change notification settings - Fork 2
[feature] Added utils file with example fns #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||
| """Utility functions for common operations.""" | ||||||||
|
|
||||||||
| import random | ||||||||
| import string | ||||||||
| from datetime import datetime | ||||||||
|
|
||||||||
|
|
||||||||
| def generate_random_string(length: int = 10) -> str: | ||||||||
| """Generate a random alphanumeric string.""" | ||||||||
| chars = string.ascii_letters + string.digits | ||||||||
| return ''.join(random.choice(chars) for _ in range(length)) | ||||||||
|
||||||||
| return ''.join(random.choice(chars) for _ in range(length)) | |
| return ''.join(random.choices(chars, k=length)) |
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is_prime() function doesn't validate that the input is actually an integer. If a float is passed (e.g., is_prime(2.5)), the function will execute but may produce unexpected behavior in the range iteration. Consider adding type validation or relying on type hints being enforced by the caller.
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fibonacci() function doesn't validate negative inputs. Calling fibonacci(-5) will return an empty list, which may be correct behavior, but the docstring doesn't specify what happens with negative or zero inputs. Consider clarifying the expected behavior in the docstring or adding explicit validation.
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The word_count() function may produce empty string keys if a word consists only of punctuation (e.g., "..." or "!!!"). After stripping all punctuation, these become empty strings. Consider filtering out empty strings: if word: counts[word] = counts.get(word, 0) + 1
| counts[word] = counts.get(word, 0) + 1 | |
| if word: | |
| counts[word] = counts.get(word, 0) + 1 |
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The word_count() function could be more efficient using collections.Counter instead of manually maintaining a dictionary: from collections import Counter; return dict(Counter(word.strip('.,!?;:') for word in text.lower().split() if word.strip('.,!?;:')))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
random.choice()function is not cryptographically secure and should not be used for generating tokens, passwords, or other security-sensitive strings. Consider usingsecrets.choice()instead for secure random string generation, or add documentation warning that this function should not be used for security purposes.