Skip to content

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 25 commits into from
Oct 14, 2020
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 Oct 11, 2020
91d8bf3
Removed the unexpected expression part.
mayur200 Oct 11, 2020
8453420
Added program for swap cases in string folder
mayur200 Oct 11, 2020
c9d1b7d
removed if condition and exchange word with char
mayur200 Oct 14, 2020
0a512bb
added '=' sign which I removed before because of unknowing error from…
mayur200 Oct 14, 2020
0315f02
added space in test
mayur200 Oct 14, 2020
018bb9f
removed costraint from problem statement
mayur200 Oct 14, 2020
d823ec1
Update cocktail_shaker_sort.py
cclauss Oct 14, 2020
94b71b4
Update naive_string_search.py
cclauss Oct 14, 2020
f8ae23b
Update swap_case.py
cclauss Oct 14, 2020
145ffe0
psf/black " not '
cclauss Oct 14, 2020
18c8286
added new line at the end of the file
mayur200 Oct 14, 2020
ab606cd
Fix flake8 issues
cclauss Oct 14, 2020
8ca8a89
added new line at the end of the file
mayur200 Oct 14, 2020
bbf21ca
Merge branch 'master' of https://github.com/mayur200/Python
mayur200 Oct 14, 2020
752bc5d
added new line at the end of the file
mayur200 Oct 14, 2020
ef73619
added True and fixed comment
mayur200 Oct 14, 2020
353eaed
python file end with \n
mayur200 Oct 14, 2020
08209ff
Update swap_case.py
cclauss Oct 14, 2020
14024a8
Update strings/swap_case.py
cclauss Oct 14, 2020
bcfcb21
Update strings/swap_case.py
cclauss Oct 14, 2020
81f89eb
Apply suggestions from code review
cclauss Oct 14, 2020
421fa61
Update strings/swap_case.py
cclauss Oct 14, 2020
30863af
Update swap_case.py
cclauss Oct 14, 2020
79d37c4
Update swap_case.py
cclauss Oct 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions strings/swap_case.py
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:")))