mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-06 22:28:49 -04:00
Add some cool queue, stacks, strings, math, bit manipulation examples (#35)
This commit is contained in:
parent
f3ee2cdf52
commit
0f455a0322
24 changed files with 932 additions and 13 deletions
26
arrays_and_strings/anagram.py
Normal file
26
arrays_and_strings/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