-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
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
Changes from 3 commits
584ce63
91d8bf3
8453420
c9d1b7d
0a512bb
0315f02
018bb9f
d823ec1
94b71b4
f8ae23b
145ffe0
18c8286
ab606cd
8ca8a89
bbf21ca
752bc5d
ef73619
353eaed
08209ff
14024a8
bcfcb21
81f89eb
421fa61
30863af
79d37c4
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 |
---|---|---|
|
@@ -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')}") | ||
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. Why break this? 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. I was getting error in pycharm 'unexpected expression part' before running a program. 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. Pycharm is not upgraded to Python 3.8 and 3.9 which support this functionality. 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. I have fixed this |
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. | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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 | ||||||
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. Why? 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. Its example for problem statement. If someone failed to understand the problem. This example is self explanatory 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. No. I mean why create a 1000 character limit? Just process the string no matter how long it is. 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. Ok. I will fix it. 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. 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]+') | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
||||||
def swap_case(sentence): | ||||||
""" | ||||||
This function will convert all lowercase letters to uppercase letters and vice versa. | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
>>>swap_case('Algorithm.Python@89') | ||||||
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.
Suggested change
Without the space, the test is never run. 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. I will fix it 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. I have added space. I have commited changes |
||||||
aLGORITHM.pYTHON@89 | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
""" | ||||||
if len(sentence) < 1001: | ||||||
newstring = '' | ||||||
for word in sentence: | ||||||
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. These are not words. They are char. 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. ok. I will fix it 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. 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") | ||||||
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. Why? 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. I have raise an exception and its readable. If its not relatable should I remove it? 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. No. I mean why create a 1000 character limit? Just process the string no matter how long it is. 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. I have removed condition |
||||||
return newstring | ||||||
|
||||||
|
||||||
if __name__ == '__main__': | ||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
s = input("Please input sentence:") | ||||||
result = swap_case(s) | ||||||
print(result) |
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.
Why break this?
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.
I was getting error in pycharm 'unexpected expression part' before running a program.
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.
I have fixed it again and I have commited changes. Sorry for the inconvenience