Introduction Python programming language is a dynamically typed language. In other words, variable types are not explicitly declared as in statically typed languages (ex. C++). Instead, type checking is performed at runtime as opposed to compile time. The debate of which is better? a dynamically typed or statically typed language is not discussed in this
Introduction Welcome to a new code snippet in Python. Today, we are going to clarify the difference between items() and iteritems() methods when using a Python dictionary. Let us first quickly refresh our memory about lists, tuples and dictionaries in Python: A list is an array data structure that can be edited A tuple is
Introduction In today’s Python code snippet, we are going to talk about deleting, removing and popping list elements: remove method: takes a value as input, searches for it, removes the first match. If the item is not found it errors out del function: removes an item at a specific index, can delete all elements or
Welcome to a new Python code snippet. In this post, we are going to suggest a couple of methods to flatten a list of lists. The final output is going to be a one dimensional list. Let us take an example: Using nested loops Using list comprehensions Using sum function Using list extend Using chain
Question Python list data structure has append() and extend() methods. Both methods add new items to the list. What is the difference between the two? Append vs extend list in Python Append: adds a new item to the end of the list. The item can be an object of any type. It could be a
Introduction In this post, we are going to discuss a rarely used Python feature. We are familiar with the regular for and while loops but using an else clause after a loop is not common. We can live without this language feature however it can be used to write elegant code. Let us take an
Welcome to a new Python code snippet. In this post, we are going to learn how to check whether a file or directory (ex. file path) exists using Python. A common use case is to check if a file exists before opening for reading or writing. Let us take some examples… Check file exists in
Introduction Given a directory path on the file system, the following Python code snippets retrieve a list of file names and total count using different methods. You may use the one that best suite your needs or find it more elegant. Let us get started… Using glob module In this example, we are going to
Set vs list in Python A better way to understand the key difference between sets and lists in Python is to understand the definition regardless of language or syntax. Generally speaking, a set is a mathematical concept which refers to a collection of distinct objects (in math they are called elements). Distinct means there are
Introduction In this tutorial, we are going to create a containerized machine learning application. It is a simple application but it can be used as a template to build a more serious one. I hope by the end of this post you will have a basic idea about the following cool topics and technologies: Machine