Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python implementation for Day 6 Problem (#71)
* Add @aaditkamat as a contributor * Add Ruby code for Day 1: FizzBuzz problem * Add Ruby code for Day 2: String reverse problem * Update README.md for Day 2 * Modify Ruby code and README * Add condition for nil and wrong type edge cases * Add a seperate Ruby source code file for palindrome * Modify code for reverse.rb * Add seperate palindrome and reverse code sections in README * Update gitignore * Refactor palindrome.rb and rename heading in README * Add solution for Day 3: Hamming Problem * Add condition for strings of unequal lengths * Update README * Change project name and owner in.all-contributorsrc * Remove merge conflict lines * Add @shivank86 as a contributor * Add C++ files for different patterns * Add author and date comments at the top of C++ files * Update README.md * Add solution for Day 6 Problem in Python * Update README * Refactor code files
- Loading branch information
1 parent
d403256
commit 5462d07
Showing
4 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,27 @@ | ||
''' | ||
@author: aaditkamat | ||
@date: 27/12/2018 | ||
''' | ||
|
||
def check_anagram(first_str, second_str): | ||
first_word_dict = {} | ||
second_word_dict = {} | ||
first_str = first_str.replace(' ', '').lower() | ||
second_str = first_str.replace(' ', '').lower() | ||
for ch in first_str: | ||
if ch not in first_word_dict: | ||
first_word_dict[ch] = 1 | ||
else: | ||
first_word_dict[ch] += 1 | ||
|
||
for ch in second_str: | ||
if ch not in second_word_dict: | ||
second_word_dict[ch] = 1 | ||
else: | ||
second_word_dict[ch] += 1 | ||
return first_word_dict == second_word_dict | ||
|
||
print("Enter two strings: ") | ||
first_str = input() | ||
second_str = input() | ||
print("Are ", first_str, "and ", second_str, "anagrams? ", check_anagram(first_str, second_str)) |
This file contains 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,14 @@ | ||
''' | ||
@author: aaditkamat | ||
@date: 27/12/2018 | ||
''' | ||
|
||
def reverse_words(string): | ||
new_string = '' | ||
for word in string.split(' '): | ||
new_string += word[::-1] + ' ' | ||
return new_string | ||
|
||
print("Enter a string: ", end= '') | ||
string = input() | ||
print("Reverse of string: ", reverse_words(string)) |
This file contains 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,21 @@ | ||
''' | ||
@author: aaditkamat | ||
@date: 27/12/2018 | ||
''' | ||
|
||
#short version | ||
from string import capwords | ||
def capitalize_sentence_short(string): | ||
return capwords(string) | ||
|
||
#slightly long version | ||
def capitalize_sentence_long(string): | ||
new_string = '' | ||
for word in string.split(' '): | ||
new_string += word.capitalize() + ' ' | ||
return new_string | ||
|
||
print("Enter a string: ", end= ' ') | ||
string = input() | ||
print("String \'", string, "\' with first letter of each word capitalized (short version): ", capitalize_sentence_short(string)) | ||
print("String \'", string, "\' with first letter of each word capitalized (slightly long version): ", capitalize_sentence_long(string)) |
This file contains 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