Functions

We have a simple function that adds two numbers

python_template.add(x, y)[source]

The sum of two numbers.

Parameters:
  • x ((int, float)) – The first number to be added.
  • y ((int, float)) – The second number to be added.
Returns:

ret – The sum of the inputs a and b

Return type:

(int, float)

Notes

Python will often convert the types of the input values. For example if the input of x and y are integers the result will be in an integer. However if the input is a integer and a float a float will be returned.

Examples

Adding two integers together:

>>> add(5, 3)
8

An example of mixed input type:

>>> add(5.0, 3)
8.0

We also have the popular Levenshtein distance estimator

python_template.text.levenshtein(seq1, seq2)[source]

Function to compute the Levenshtein distance between two strings. Reference: https://en.wikipedia.org/wiki/Levenshtein_distance

Parameters:
  • seq1 (str) – The first string to compare
  • seq2 (str) – The second string to compare
Returns:

distance – The Levenshtein distance between two strings

Return type:

int

Notes

The Levenshtein distance between two words is the minimum number of single-character edits required to change one word into the other. This is often very useful for finding approximate string matches. For example throwing an error with suggestions due to a keyword mismatch.

Examples

Find the distance between kitten and sitting:

>>> levenshtein("kitten", "sitting")
3