# Blog Posts tagged with 'python'

## Quicksort Algorithm in Python

Today, in one of my algorithms design and analysis classes I learned about Quicksort. Much like Merge Sort, Quicksort is a divide and conquer sorting algorithm that sorts the items in O(nlogn). In this article I will be writing a Quicksort function in Python.

## Python Fibonacci Number Generator

I mentioned learning about generating Fibonacci numbers using Python in my computer science and algorithm courses using recursive functions and Dynamic Programming. I wrote an article about the differences: Fibonacci Numbers - Tale of Two Algorithms using Python. In this article I show a Fibonacci Number Generator using Python generators. I also talk more about Python generators as well as mention the differences between `range` and `xrange` in Python 2.7.

## Algorithm to Make Change in Python - Dynamic Programming

Making change is another classic example of Dynamic Programming I learned in my algorithms classes. In this example, I use Python to make change for a certain dollar amount given a list of dollars in U.S. currency. The goal is to make change using the least number of bills. Dynamic Programming is a great solution for this, since the problem involves overlapping sub-problems.

## Dynamic Programming in Python for Clash of Clans

Using Dynamic Programming in Python to solve the Knapsack Problem in Clash of Clans. The goal is to find the best troop composition to hide the maximum amount of elixir and dark elixir in my barracks!

## Entity Framework Core Example Using SQLAlchemy

Taking the example code I wrote with Entity Framework Core and C# and performing the same O/R Mapping and SQL Commands using SQLAlchemy and Python to perform CRUD operation on a SQLite Database.

## Insertion Sort Using Python

A solution to insertion sort using Python that I wrote with Pythonista on my iPad Pro. I have also included several Doctests to verify it is sorting a list of integers correctly using insertion sort. If you are attending computer science and algorithms courses like myself, I hope you find the code useful!

## Caesar Cipher in Python - Classical Cryptography

My computer science assignment was to develop a class in Python that encrypts and decrypts messages using the Caesar Cipher. I chose this solution, because it was the most creative by using Python string constants, the zip function to create a tuple from 2 iterable lists, dictionaries for constant lookup, and list comprehensions for doing the actual encryption and decryption.

## Python Training - Selection Sort with Sample Unit Tests

I am learning Python and taking several online courses on computer science and algorithms. One of my assigments is to write Selection Sort in Python. I wrote this sample code on my iPad Pro using Pythonista and included unit tests.

## ASP.NET Core Web API on macOS Using Visual Studio Code

In this article I create an ASP.NET Core Web API Application and Python web client on macOS that allows me to list, add, and remove daily reminders. I also show how to register services with the ASP.NET Core Dependency Injection Framework. I use Visual Studio Code to build the Web API Application and PyCharm to build the Python web client.

## Merge Sort in Python Using Pythonista 3 on iPad Pro

I am learning divide and conquer algorithms and wrote Merge Sort in Python using Pythonista 3 on my iPad Pro. I included Doctests this time and plan to do so in the future. The Doctests provided a sanity check when I changed my algorithm based on an optimization I found elsewhere.

## Python Web Client Retrieving Factorial Calculations from ASP.NET Core Website

As promised, I wrote a Python client using the Requests http library to use the factorial service I built with ASP.NET Core Routing, RouteBuilder.MapGet, and a custom RequestDelegate. I just made a small tweak to the RequestDelegate to support a custom http header for returning just the factorial instead of a formatted string.

## Binary Search Example in Python

Binary search is a very efficient algorithm for finding an item in a sorted list. I wrote a Python program that uses binary search to find random numbers in a list of 10,000 and 100,000 items. Using asymptotic notation, binary search is O(log n), which means it has a really slow rate of growth as the number of items to search grows large.

## Fibonacci Numbers - Tale of Two Algorithms using Python

A mind blowing experiment looking at two different algorithms in Python for calculating Fibonacci numbers. One is the well-known recursive function, and the other is an alternative algorithm using a list. I profiled these functions in Pycharm, and am amazed at the results!

## Python Algorithms - Revisiting Recursive Functions and Palindromes

My algorithms course has me re-thinking that recursive function used to detect palindromes. Although the assignment required writing a recursive function, is a recursive function really the best algorithm? Possibly, but there is at least one other good solution.

## Python Sets and the Hangman Game

I built another helper function for the Hangman Game. This function also leverages the set data structure in Python. I really love the use of sets in this instance as well as the instance before. Python sets bring out the essence of the function's purpose and promotes declarative programming.

## Python Recursive Function to Detect Palindromes

I wrote a recursive function in Python to determine if a string was a palindrome. While doing so I also wrote one of my first Python List Comprehensions to strip non-alphanumeric characters from the string before testing to see if it was a palindrome.

## Programming the Hangman Game in Python

I am creating a helper function in Python for the game Hangman. I need to determine if the secret word has been guessed from a list of guesses. I mention imperative vs. declarative programming, recursion, and sets and subsets in Python.