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
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion sorts/cocktail_shaker_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ def cocktail_shaker_sort(unsorted: list) -> list:
doctest.testmod()
user_input = input("Enter numbers separated by a comma:\n").strip()
unsorted = [int(item) for item in user_input.split(",")]
print(f"{cocktail_shaker_sort(unsorted) = }")
print(f"{cocktail_shaker_sort(unsorted) }")
Copy link
Member

Choose a reason for hiding this comment

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

Why break this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting error in pycharm 'unexpected expression part' before running a program.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed it again and I have commited changes. Sorry for the inconvenience

2 changes: 1 addition & 1 deletion strings/naive_string_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def naive_pattern_search(s: str, pattern: str) -> list:

if __name__ == "__main__":
assert naive_pattern_search("ABCDEFG", "DE") == [3]
print(f"{naive_pattern_search('ABAAABCDBBABCDDEBCABC', 'ABC') = }")
print(f"{naive_pattern_search('ABAAABCDBBABCDDEBCABC', 'ABC')}")
Copy link
Member

Choose a reason for hiding this comment

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

Why break this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting error in pycharm 'unexpected expression part' before running a program.

Copy link
Member

Choose a reason for hiding this comment

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

Pycharm is not upgraded to Python 3.8 and 3.9 which support this functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed this

48 changes: 48 additions & 0 deletions strings/swap_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'''
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

Constraints: Length of string should between 1 and 1000
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its example for problem statement. If someone failed to understand the problem. This example is self explanatory

Copy link
Member

Choose a reason for hiding this comment

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

No. I mean why create a 1000 character limit? Just process the string no matter how long it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I will fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed it and I have pushed changes



'''
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')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
>>>swap_case('Algorithm.Python@89')
>>> swap_case('Algorithm.Python@89')

Without the space, the test is never run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added space. I have commited changes

aLGORITHM.pYTHON@89
"""
if len(sentence) < 1001:
newstring = ''
for word in sentence:
Copy link
Member

Choose a reason for hiding this comment

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

These are not words. They are char.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I will fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed it and commit the changes

if word.isupper() == True:
newstring += word.lower()
if word.islower() == True:
newstring += word.upper()
if regexp.search(word):
newstring += word

else:
raise Exception("Charater length should be between 1 and 1000")
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

@mayur200 mayur200 Oct 13, 2020

Choose a reason for hiding this comment

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

I have raise an exception and its readable. If its not relatable should I remove it?

Copy link
Member

Choose a reason for hiding this comment

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

No. I mean why create a 1000 character limit? Just process the string no matter how long it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed condition

return newstring


if __name__ == '__main__':
s = input("Please input sentence:")
result = swap_case(s)
print(result)