CSV Operations 101 — with Python's Own csv Module

There is a great chance that you have come across, or have to work with a CSV (comma-separated values) file. A CSV file holds data similar to a spreadsheet. It separates the values with a delimiter character, so it does not always have to be a comma. However, since it is a comma-separated values file, let’s see an example as such:

Read More

Simple Implementation of Stacks and Queues with Deque in Python

Two of the abstract data types that you are most likely to have encountered before are stacks and queues. One important aspect is that each of them has different principles when it comes to their behavior when inserting and removing elements — LIFO (last in, first out) for stacks, FIFO (first in, first out) for queues. With a stack, the last item inserted is the first to go out, so, we push and pop from one end of the stack. With a queue, the first item inserted is going to be removed first, similar to a queue in real life, so, enqueue and dequeue operations are done from the opposite ends of the queue.

Read More

Solving the Problem Sets of CS50's Introduction to Programming with Python — One at a Time: Final Project and Beyond

The final week has arrived, and today we do not have any problem sets. Before anything, give yourself a pat on the back for coming this far! It has been quite a delightful journey. We have started with the basic blocks of programming, variables and functions, dealt with flow control using conditionals, iterated with loops, handled exceptions, scratched the surface of the world of Python libraries, written tests for our programs to make sure that they work as we intend them to do, worked with files, learned to love regular expressions, and last week, peeked into the realm of object-oriented programming. Today in et cetera we will be looking at some other tools in our toolkit. Phew! If you have started this journey from absolute zero, you have indeed come far! Even if you already have some knowledge before starting the course, congratulations to you as well! It is not easy to dedicate oneself through all these weeks. You can always find the posts on previous problem sets in the archive as well.

Read More

Solving the Problem Sets of CS50's Introduction to Programming with Python — One at a Time: Problem Set 8

This week, we are solving the last problem set of the course. We have covered so much, solved many beautiful problems, and after this week, are ready to implement our very own final project! I know that is a bit emotional indeed, but let me give the disclaimer one last time, that this series was intended as a guide for thinking about the problems, instead of just providing the solutions. And, as always, it is assumed you have read the problem explanations already. You can find the previous posts in this series in the archive.

Read More

Solving the Problem Sets of CS50's Introduction to Programming with Python — One at a Time: Problem Set 6

This week on File I/O, we have exciting new problems to solve. Working with files programmatically is inevitable, and as always, Python makes our life easier — with many useful libraries. As always, I assume you have read the problem explanations on this week’s Problem Set, and have to give the disclaimer that you are not going to find any full solutions to these problems here, but rather gain some insights into how to think about them.

Read More