mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-22 16:31:15 -04:00
Rename anagram.py to is_anagram.py
This commit is contained in:
parent
f4e431412e
commit
0ad1ab44be
1 changed files with 0 additions and 0 deletions
26
arrays_and_strings/is_anagram.py
Normal file
26
arrays_and_strings/is_anagram.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
|
||||
def is_anagram(string1, string2) -> bool:
|
||||
|
||||
string1 = string1.lower()
|
||||
string2 = string2.lower()
|
||||
|
||||
if len(string1) != len(string2):
|
||||
return False
|
||||
|
||||
for char in string1:
|
||||
if char not in string2:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
print('Testing is_anagram()...')
|
||||
string1 = "listen"
|
||||
string2 = "silent"
|
||||
print(f'Is {string1} an anagram of {string2}?: {is_anagram(string1, string2)}')
|
Loading…
Add table
Add a link
Reference in a new issue