How Python implements dictionaries

Jessica YungProgrammingLeave a Comment

Python Dictionaries: Not even a space-time tradeoff If you could choose to store things that you’d want to look up later in a Python dictionary or in a Python list, which would you choose? It turns out that looking up items in a Python dictionary is much faster than looking up items in a Python list. If you search for … Read More

What makes Numpy Arrays Fast: Memory and Strides

Jessica YungMachine Learning, ProgrammingLeave a Comment

How is Numpy so fast? In this post we find out how Numpy’s ndarray is stored and how it is usually manipulated by Numpy functions using strides. Getting to know the ndarray A NumPy ndarray is a N-dimensional array. You can create one like this:

These arrays are homogenous arrays of fixed-sized items. That is, all the items in … Read More

List Comprehensions in Python

Jessica YungProgrammingLeave a Comment

1. What are list comprehensions? List comprehensions construct lists in natural-to-express ways. They can replace map-filter combinations and many for loops. They’re just syntactic sugar. That means they make your code easier to read (and prettier). Example 1: For loops -> List comprehension

Example 2: Map-filter -> List Comprehension

(I will do a post on map and filter and … Read More

Unit Tests and Doctests in PyCharm

Jessica YungProgrammingLeave a Comment

Yesterday I thought it was finally time to try an IDE (Integrated Development Environment. I downloaded PyCharm Community (free) which many friends use and recommend. What’s an IDE? An IDE in an integrated development environment. It contains tools that make developers’ lives easier. PyCharm, an IDE for Python, contains a source code editor with code refactoring, build automation tools, a debugger, … Read More

Code Wars: Consecutive Strings Programming Problem

Jessica YungProgrammingLeave a Comment

Woe is me, I am a terrible programmer. Spoiler alert: Scroll down for terrible code followed by elegant code. Question You are given an array strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array. Example: longest_consec([“zone”, “abigail”, “theta”, “form”, “libe”, “zas”, “theta”, “abigail”], 2) … Read More

Big O Notation: A Common Mistake and Documentation

Jessica YungProgrammingLeave a Comment

A Question What’s the time complexity of the following algorithm? (Don’t know how to calculate that? Here’s a nice intro to Big-O Notation from InterviewCake.)

O(n^2)?  Nope. If array_x has length x and array_y has length y, the algorithm has time complexity O(xy) since one loop with a constant number of operations is run y times for each iteration of … Read More