-
-
Notifications
You must be signed in to change notification settings - Fork 46k
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
fixes join.py and split.py action and requirements error #12438
Open
sanks011
wants to merge
10
commits into
TheAlgorithms:master
Choose a base branch
from
sanks011:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
23a0f95
fixes join.py action
sanks011 29b5cc2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8243480
fixes split.py
sanks011 376b637
Merge branch 'master' of https://github.com/sanks011/Python
sanks011 f6c545f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] de9aa38
Fixed two requirements
sanks011 0b45a6d
Custom Implementation of join.py
sanks011 ae09865
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fb63afe
updated join.py
sanks011 b9d9cb3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,49 @@ | ||
""" | ||
Program to join a list of strings with a separator | ||
""" | ||
|
||
|
||
def join(separator: str, separated: list[str]) -> str: | ||
""" | ||
Joins a list of strings using a separator | ||
and returns the result. | ||
Custom implementation of the join() function. | ||
This function manually concatenates the strings in the list, | ||
using the provided separator, without relying on str.join(). | ||
|
||
:param separator: Separator to be used | ||
for joining the strings. | ||
:param separated: List of strings to be joined. | ||
:param separator: The separator to place between strings. | ||
:param separated: A list of strings to join. | ||
|
||
:return: Joined string with the specified separator. | ||
:return: A single string with elements joined by the separator. | ||
|
||
Examples: | ||
:raises Exception: If any element in the list is not a string. | ||
|
||
Examples: | ||
>>> join("", ["a", "b", "c", "d"]) | ||
'abcd' | ||
>>> join("#", ["a", "b", "c", "d"]) | ||
'a#b#c#d' | ||
>>> join("#", "a") | ||
'a' | ||
>>> join("#", "a") # Single string instead of list | ||
Traceback (most recent call last): | ||
... | ||
Exception: join() accepts only strings | ||
>>> join(" ", ["You", "are", "amazing!"]) | ||
'You are amazing!' | ||
|
||
This example should raise an | ||
exception for non-string elements: | ||
>>> join("#", ["a", "b", "c", 1]) | ||
Traceback (most recent call last): | ||
... | ||
Exception: join() accepts only strings | ||
|
||
Additional test case with a different separator: | ||
>>> join("-", ["apple", "banana", "cherry"]) | ||
'apple-banana-cherry' | ||
>>> join(",", ["", "", ""]) | ||
',,' | ||
""" | ||
|
||
joined = "" | ||
for word_or_phrase in separated: | ||
result = "" | ||
for i, word_or_phrase in enumerate(separated): | ||
# Check if the element is a string | ||
if not isinstance(word_or_phrase, str): | ||
raise Exception("join() accepts only strings") | ||
joined += word_or_phrase + separator | ||
|
||
# Remove the trailing separator | ||
# by stripping it from the result | ||
return joined.strip(separator) | ||
# Add the current word or phrase to the result | ||
result += word_or_phrase | ||
# Add the separator if it's not the last element | ||
if i < len(separated) - 1: | ||
result += separator | ||
|
||
return result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kaaserne can you please review it? |
||
|
||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's the reason these got removed? I've never used
doctest
before but I think this has something to do with testing. Maybe you can also add: