-
- Notifications
You must be signed in to change notification settings - Fork 49.1k
Added strings programs in data structure folder #13407
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
for more information, see https://pre-commit.ci
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| from collections import Counter | ||
| | ||
| | ||
| def are_anagrams(s1, s2): | ||
| 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. As there is no test file in this pull request nor any test function or class in the file Please provide return type hint for the function: Please provide type hint for the parameter: Please provide type hint for the parameter: | ||
| return Counter(s1) == Counter(s2) | ||
| | ||
| | ||
| # Example | ||
| print("Anagram:", are_anagrams("listen", "silent")) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| def char_frequency(s): | ||
| Check failure on line 1 in data_structures/strings/frequencyofeachchar.py | ||
| 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. As there is no test file in this pull request nor any test function or class in the file Please provide return type hint for the function: Please provide type hint for the parameter: Please provide descriptive name for the parameter: | ||
| freq = {} | ||
| for char in s: | ||
| freq[char] = freq.get(char, 0) + 1 | ||
| return freq | ||
| | ||
| | ||
| # Example | ||
| print(char_frequency("datastructure")) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| def reverse_words(sentence): | ||
| Check failure on line 1 in data_structures/strings/reverseword.py | ||
| 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. As there is no test file in this pull request nor any test function or class in the file Please provide return type hint for the function: Please provide type hint for the parameter: | ||
| words = sentence.split() | ||
| stack = [] | ||
| for word in words: | ||
| stack.append(word) | ||
| reversed_sentence = ' '.join(stack[::-1]) | ||
| reversed_sentence = " ".join(stack[::-1]) | ||
| return reversed_sentence | ||
| | ||
| | ||
| # Example | ||
| print(reverse_words("Data Structures in Python")) | ||
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.
As there is no test file in this pull request nor any test function or class in the file
data_structures/strings/allunique.py, please provide doctest for the functionhas_unique_charsPlease provide return type hint for the function:
has_unique_chars. If the function does not return a value, please provide the type hint as:def function() -> None:Please provide type hint for the parameter:
sPlease provide descriptive name for the parameter:
s