-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Added swap case program and removed unexpected expression part #3212
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
584ce63
Removed an extra '=' which was creating an error while running a prog…
mayur200 91d8bf3
Removed the unexpected expression part.
mayur200 8453420
Added program for swap cases in string folder
mayur200 c9d1b7d
removed if condition and exchange word with char
mayur200 0a512bb
added '=' sign which I removed before because of unknowing error from…
mayur200 0315f02
added space in test
mayur200 018bb9f
removed costraint from problem statement
mayur200 d823ec1
Update cocktail_shaker_sort.py
cclauss 94b71b4
Update naive_string_search.py
cclauss f8ae23b
Update swap_case.py
cclauss 145ffe0
psf/black " not '
cclauss 18c8286
added new line at the end of the file
mayur200 ab606cd
Fix flake8 issues
cclauss 8ca8a89
added new line at the end of the file
mayur200 bbf21ca
Merge branch 'master' of https://github.com/mayur200/Python
mayur200 752bc5d
added new line at the end of the file
mayur200 ef73619
added True and fixed comment
mayur200 353eaed
python file end with \n
mayur200 08209ff
Update swap_case.py
cclauss 14024a8
Update strings/swap_case.py
cclauss bcfcb21
Update strings/swap_case.py
cclauss 81f89eb
Apply suggestions from code review
cclauss 421fa61
Update strings/swap_case.py
cclauss 30863af
Update swap_case.py
cclauss 79d37c4
Update swap_case.py
cclauss 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
This algorithm helps you to swap cases. | ||
|
||
User will give input and then program will perform swap cases. | ||
|
||
In other words, convert all lowercase letters to uppercase letters and vice versa. | ||
For example: | ||
1. Please input sentence: Algorithm.Python@89 | ||
aLGORITHM.pYTHON@89 | ||
2. Please input sentence: github.com/mayur200 | ||
GITHUB.COM/MAYUR200 | ||
|
||
""" | ||
import re | ||
|
||
# This re.compile() function saves the pattern from 'a' to 'z' and 'A' to 'Z' | ||
# into 'regexp' variable | ||
regexp = re.compile("[^a-zA-Z]+") | ||
|
||
|
||
def swap_case(sentence): | ||
""" | ||
This function will convert all lowercase letters to uppercase letters | ||
and vice versa. | ||
|
||
>>> swap_case('Algorithm.Python@89') | ||
'aLGORITHM.pYTHON@89' | ||
""" | ||
new_string = "" | ||
for char in sentence: | ||
if char.isupper(): | ||
new_string += char.lower() | ||
if char.islower(): | ||
new_string += char.upper() | ||
if regexp.search(char): | ||
new_string += char | ||
|
||
return new_string | ||
|
||
|
||
if __name__ == "__main__": | ||
print(swap_case(input("Please input sentence:"))) |
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.
Uh oh!
There was an error while loading. Please reload this page.