"Calculates the Levenshtein distance between a and b."
n, m = len(a), len(b)
if n > m:
# Make sure n <= m, to use O(min(n,m)) space
a,b = b,a
n,m = m,n
current = range(n+1)
for i in range(1,m+1):
previous, current = current, [i]+*n
for j in range(1,n+1):
add, delete = previous[j]+1, current[j-1]+1
change = previous[j-1]
if a[j-1] != b[i-1]:
change = change + 1
current[j] = min(add, delete, change)
from sys import argv
Linked from: http://people.cs.pitt.edu/~kirk/cs1501/Pruhs/Fall2006/Assignments/editdistance/Levenshtein%20Distance.htm
Question: Why am I getting the following error in Python “ImportError: No module named py”?
Simple answer: Somewhere, one of your imports ends in “.py” Deleting that should solve the issue.
Python is trying to import the package named “test” with a module named “py” that doesn’t exist within the file “test.py”
Correct way of importing “test.py”
The Qt Designer allows you to subclass/extend a widget by “promoting” the base class and then specifying a header file that contains your defined class. If the header file variable in Qt Designer has “.py” you also get the error when your GUI is compiled. The incorrect inclusion of “testlistview.py”:
When working with Gnu Privacy Guard (GnuPG 1.4.x) it is not necessary to have a full installation . The necessary files:
Optional but necessary to download keys from key servers:
I needed to install the following from wheels (.whl file):
- Twisted – Twisted-15.5.0-cp27-none-win32.whl
- lxml – lxml-3.5.0-cp27-none-win32.whl
and upgrade cryptography
pip install cryptography –upgrade
Get the wheels from http://www.lfd.uci.edu/~gohlke/pythonlibs/
Microsoft now provides the solution as a msi install package for Microsoft Visual C++ Compiler for Python 2.7
If that still doesn’t work you can try installing the pre-compiled wheel from: http://www.lfd.uci.edu/~gohlke/pythonlibs/
If installed using the default location pip is located at:
Open a command window there and use the command
pip install <package name>
- package name – is replaced by the name of the package that needs installation e.g.:
pip install scrapy
I like the clean formatting and explanation from skorks.com and used a similar formatting here.
Month List: index starts at 1
compatible with datetime module date.month
monthList is an empty string
monthList = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
Weekday List: index starts at 0
compatible with datetime module date.weekday()
weekdayList = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
Using isoweekday()? get the list here
Python String Lowercase
use “.lower()” example dayName.lower()
Python String Replace
str.replace(old, new[, max])
Python String Range Slice (Trim)
Python datetime double digit month and day values
Python Print Newline
The error message “… is not a supported wheel on this platform.” means there is some incompatibility between the wheel package and your version of Python.
Two common sources of this error are that…
- the package expects a different system type (32-bit vs 64-bit).
- your system doesn’t have or can’t identify the necessary version of Python i.e. you only have a 3.x version installed, but the package requires Python 2.7.
Fix for Issue 1
The fix is either to download the other version (32-bit if you downloaded 64-bit and vice versa) or change the wheel’s file name if you know you need the version you have.
Installing again using the new file name should successfully install the package.
Fix for Issue 2
You will need to ensure the version of Python you have and the version the package expects are the same. You might have to either install a different version of python or a different version of the package. If the package only supports a certain version of Python, then the only fix is to download the required Python version.
Where to find wheel packages?
Unofficial Windows Binaries for Python Extension Packages – http://www.lfd.uci.edu/~gohlke/pythonlibs/
Python packages I’ve had this issue with: