Consider using collections.counter
:
import collections
s1 = "Army"
s2 = "Mary"
s3 = "Zary"
def anagram(s1,s2):
return collections.Counter(s1.lower()) == collections.Counter(s2.lower())
print anagram(s1,s2) # True
print anagram(s1, s3) # False
Try it here!
More Related Contents:
- Handling numbers in lists (Python) [duplicate]
- Proper way to declare custom exceptions in modern Python?
- How do I get the path of the current executed file in Python?
- While Loop Locks Application
- Python Requests – No connection adapters
- Meaning of inter_op_parallelism_threads and intra_op_parallelism_threads
- How to extract info within a #shadow-root (open) using Selenium Python?
- How can I make an Image with a transparent Backround in Pygame?
- Generate password in python
- How can I “zip sort” parallel numpy arrays?
- Why is an MD5 hash created by Python different from one created using echo and md5sum in the shell?
- 5 maximum values in a python dictionary
- Ensuring subprocesses are dead on exiting Python program
- Difference between “grid” and “pack” geometry managers
- Why program functionally in Python?
- In Python how should I test if a variable is None, True or False
- How to set the pandas dataframe data left/right alignment?
- Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?
- How to customise error response in FastAPI?
- How to call a script from another script?
- Plotting time in with Matplotlib
- Case insensitive unique model fields in Django?
- When using os.execlp, why `python` needs `python` as argv[0]
- Vim autocomplete for Python
- AttributeError while adding colorbar in matplotlib
- How can I convert string values from a dictionary, into int/float datatypes?
- Changing certain values in multiple columns of a pandas DataFrame at once
- Embedding Python in C, linking fails with undefined reference to `Py_Initialize’
- How can I share a class between processes?
- How to make a large file accessible to external APIs?