Skip to content
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

Anagram finder #44

Merged
merged 39 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4da5808
Updated test_dummy and fixed Pylint warnings for Anagram-Finder tests
Frank2446-dotcom Jan 7, 2025
8bfcdb5
Updated test_dummy and fixed Pylint warnings for Anagram-Finder tests
Frank2446-dotcom Jan 7, 2025
29e7a74
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 11, 2025
a61371f
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 11, 2025
2a7afa2
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 11, 2025
6815cdc
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 12, 2025
56e58cc
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 12, 2025
bbbd711
Added anagram finder files
Frank2446-dotcom Jan 12, 2025
0f321a8
Added anagram finder files
Frank2446-dotcom Jan 12, 2025
5576042
Merge branch 'main' into Anagram-Finder
Frank2446-dotcom Jan 12, 2025
3fd6e39
Delete solutions/Remove_Duplicates.py
Frank2446-dotcom Jan 12, 2025
596e83c
Delete solutions/Swap_letters.py
Frank2446-dotcom Jan 12, 2025
ee3ed85
Delete solutions/Time_Conversion.py
Frank2446-dotcom Jan 12, 2025
5cf7986
Delete solutions/calculate_square_area.py
Frank2446-dotcom Jan 12, 2025
b1f5b2f
Delete solutions/check_number_type.py
Frank2446-dotcom Jan 12, 2025
b8e7d65
Delete solutions/convert_hours_to_minutes.py
Frank2446-dotcom Jan 12, 2025
ff41e76
Delete solutions/convert_to_capital.py
Frank2446-dotcom Jan 12, 2025
8d92e71
Delete solutions/convert_to_uppercase.py
Frank2446-dotcom Jan 12, 2025
de406f7
Delete solutions/is_palindrome.py
Frank2446-dotcom Jan 12, 2025
23ceae8
Delete solutions/sum_of_list.py
Frank2446-dotcom Jan 12, 2025
87cc3be
Delete solutions/merge_dictionaries.py
Frank2446-dotcom Jan 12, 2025
07f01e1
Delete solutions/word_frequency.py
Frank2446-dotcom Jan 12, 2025
4307189
Delete solutions/largest_number.py
Frank2446-dotcom Jan 12, 2025
99b9c12
Delete solutions/tests/test_Remove_Duplicate.py
Frank2446-dotcom Jan 12, 2025
d3d477c
Delete solutions/tests/test_Swap_letters.py
Frank2446-dotcom Jan 12, 2025
3eb1709
Delete solutions/tests/test_Time_Conversion.py
Frank2446-dotcom Jan 12, 2025
2891407
Delete solutions/tests/test_calculate_square_area.py
Frank2446-dotcom Jan 12, 2025
596938d
Delete solutions/tests/test_check_number_type.py
Frank2446-dotcom Jan 12, 2025
9f42d3c
Delete solutions/tests/test_convert_hours_to_minutes.py
Frank2446-dotcom Jan 12, 2025
b206050
Delete solutions/tests/test_convert_to_capital.py
Frank2446-dotcom Jan 12, 2025
d63ba20
Delete solutions/tests/test_convert_to_uppercase.py
Frank2446-dotcom Jan 12, 2025
6435bd1
Delete solutions/tests/test_is_palindrome.py
Frank2446-dotcom Jan 12, 2025
138c90a
Delete solutions/tests/test_largest_number.py
Frank2446-dotcom Jan 12, 2025
bf19fc9
Delete solutions/tests/test_merge_dictionaries.py
Frank2446-dotcom Jan 12, 2025
f0f54b7
Delete solutions/tests/test_sum_of_list.py
Frank2446-dotcom Jan 12, 2025
8512058
Delete solutions/tests/test_word_frequency.py
Frank2446-dotcom Jan 12, 2025
2beadd6
Update README.md
Frank2446-dotcom Jan 12, 2025
e7c7486
Update README.md
Frank2446-dotcom Jan 12, 2025
5908452
Update README.md
Frank2446-dotcom Jan 12, 2025
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 .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@
"source.organizeImports.ruff": "explicit"
}
},
"cSpell.words": ["unittests"]
"cSpell.words": ["dcbae", "doctests", "unittests"]
}
35 changes: 21 additions & 14 deletions solutions/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
# Solutions

## Merge Dictionaries Solution
This folder contains implementations for the challenges.

This repository contains a Python solution to merge two dictionaries.
The solution merges two dictionaries by resolving conflicts based on an optional
conflict resolution function.
## Challenges

### Features
1. **Merge Dictionaries**:
- A utility to merge two dictionaries with conflict resolution.
- See `merge_dictionaries.py` for the implementation.

- Merges two dictionaries.
- Resolves conflicts with a custom function, or by default, `dict2` overwrites `dict1`.
2. **Anagram Finder**:
- A function to check if two strings are anagrams.
- See `anagram_finder.py` for the implementation.

## Usage

To use any solution, simply import the
required function and pass the appropriate arguments.

### How to Run

1. Clone the repository.
2. Install dependencies (if any).
3. Run the tests:
2. Navigate to the folder containing the solution.
3. Run the desired script:

```bash
python -m unittest solutions/tests/test_merge_dictionaries.py
python <script_name>.py
```

### Example

```python
dict1 = {"a": 1, "b": 2}
dict2 = {"b": 3, "c": 4}
merged = merge_dictionaries(dict1, dict2)
print(merged) # Output: {'a': 1, 'b': 3, 'c': 4}
# Example for Anagram Finder
from anagram_finder import are_anagrams

result = are_anagrams("listen", "silent")
print(result) # Output: True
50 changes: 0 additions & 50 deletions solutions/Remove_Duplicates.py

This file was deleted.

39 changes: 0 additions & 39 deletions solutions/Swap_letters.py

This file was deleted.

65 changes: 0 additions & 65 deletions solutions/Time_Conversion.py

This file was deleted.

63 changes: 63 additions & 0 deletions solutions/anagram_finder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
Anagram Finder Module

This module provides a function to determine if two strings are anagrams of each other.
It checks if the strings are anagrams, handling edge cases like empty strings, special characters, and case-insensitivity.

Created on 12 01 2025
@author: Frankline Ambetsa
"""


def anagram_finder(string1: str, string2: str) -> bool:
"""
Frank2446-dotcom marked this conversation as resolved.
Show resolved Hide resolved
Check if two strings are anagrams of each other.

Anagrams are words or phrases made by rearranging the letters of another word or phrase.
This function will check for anagram status while ignoring spaces and case sensitivity.

Args:
string1 (str): The first string.
string2 (str): The second string.

Returns:
bool: True if the strings are anagrams, False otherwise.

Raises:
ValueError: If any string is empty except when both are empty.

>>> anagram_finder("listen", "silent")
True
>>> anagram_finder("evil", "vile")
True
>>> anagram_finder("hello", "world")
False
>>> anagram_finder("a gentleman", "elegant man")
True
>>> anagram_finder("clint eastwood", "old west action")
True
"""

# Defensive assertions for valid string inputs
assert isinstance(string1, str), "string1 must be a string"
assert isinstance(string2, str), "string2 must be a string"

# If any string is empty, raise an error, unless both are empty
if string1 == "" and string2 == "":
return True # Both empty strings are considered anagrams of each other

if string1 == "":
raise AssertionError("string1 cannot be empty")
if string2 == "":
raise AssertionError("string2 cannot be empty")

# To Remove spaces and convert to lowercase
string1 = string1.replace(" ", "").lower()
string2 = string2.replace(" ", "").lower()

# Check if sorted strings are equal (anagram check)
return sorted(string1) == sorted(string2)


Frank2446-dotcom marked this conversation as resolved.
Show resolved Hide resolved
if __name__ == "__main__":
pass
44 changes: 0 additions & 44 deletions solutions/calculate_square_area.py

This file was deleted.

59 changes: 0 additions & 59 deletions solutions/check_number_type.py

This file was deleted.

Loading
Loading