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

Explaining TensorFlow code for a Multilayer Perceptron

Jessica YungHighlights, Programming, Self-Driving Car NDLeave a Comment

In this post we go through the code for a multilayer perceptron in TensorFlow. We will use Aymeric Damien’s implementation. I recommend you have a skim before you read this post. I have included the key portions of the code below. 1. Code Here are the relevant network parameters and graph input for context (skim this):

Here is the model … Read More

Programming Problem Patterns #1

Jessica YungProgrammingLeave a Comment

Want to know common patterns in programming problems and mistakes people might make? Then this series is for you. In these posts I will document my main takeaways from doing programming problems and mistakes I make, whether they be outright errors or suboptimal code chunks. Each post has two parts: the problem statement and notes. I may include the solution … 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

Automate running a script using crontab

Jessica YungProgrammingLeave a Comment

Problem: You want to run a script once every 5 minutes or at some other regular interval, but don’t want to do it manually. You will need: Access to your UNIX (Any *nix should work) shell A script you want to run. If you don’t have a script you want to run, you can follow along with <a href="https://github.com/jessicayung/blog-code-snippets/blob/master/record_time.py" target="_blank">record_time.py</a> that appends a … Read More