Why not just sort the strings?
>>> sorted('anagram')
['a', 'a', 'a', 'g', 'm', 'n', 'r']
>>> sorted('nagaram')
['a', 'a', 'a', 'g', 'm', 'n', 'r']
>>> sorted('anagram') == sorted('nagaram')
True
More Related Contents:
- Using Python, find anagrams for a list of words
- How on earth does this code work
- What’s the correct way to convert bytes to a hex string in Python 3?
- Programmatically saving image to Django ImageField
- check what files are open in Python
- Beautiful Soup findAll doesn’t find them all
- Pandas GroupBy and select rows with the minimum value in a specific column
- networkx – change color/width according to edge attributes – inconsistent result
- Get the string within brackets in Python
- Child processes created with python multiprocessing module won’t print
- How to use custom png image marker with plot?
- How to get current time in python and break up into year, month, day, hour, minute?
- Pandas – Number of Months Between Two Dates
- numpy arbitrary precision linear algebra
- How do I convert a list in a Pandas DF into a string?
- How do I put a constraint on SciPy curve fit?
- How to append rows in a pandas dataframe in a for loop?
- Right-to-left string replace in Python?
- “Must construct a QApplication before a QPaintDevice” from QWidget
- How can I move the ball instead of leaving a trail all over the screen in pygame?
- Converting images to csv file in python
- how to center image inside a rect pygame
- How do I raise the same Exception with a custom message in Python?
- Difference between consecutive elements in list [duplicate]
- How to test that variable is not equal to multiple things?
- Python list([]) and []
- How to obtain a Thread id in Python?
- Why use **kwargs in python? What are some real world advantages over using named arguments?
- Why doesn’t the operator module have a function for logical or?
- How to extend distutils with a simple post install script?