Pieces of Py

The whole thought behind Pieces of Py is to write down things that I have picked up during my journey learning the Python language. The purpose is, on one hand, to have easy access finding my way back, when it is useful in other contexts. But also to write down and describe what I have learned with code examples, as to better state the knowledge I have gathered.

Publicly posting them on my blog is a way to perhaps support others learning Python.

So Pieces of Py is not meant to be tutorials or descriptions of how to build an entire app, it is rather a way to describe different concepts within common areas within Python that I have learnt. In a way, it is my developer notes.

Pieces of py image

Pieces of Py #5 Slice me up

Posted on Tue 17 September 2019 in Python • Tagged with Python, Pieces of Py, Slicing • 3 min read

In my learnings of Python I came to know that there is something called slicing. Given a sequence that you want to get certain sub-elements from, you can more easily get the results you want with slicing, instead of e.g. making a couple of for-loops.

Lets start with taking …

Continue reading

Pieces of Py #4 Using itertools.groupby

Posted on Sun 01 September 2019 in Python • Tagged with Python, Pieces of Py, Itertools • 3 min read

During some of the exercises I did on my first round of #100DaysOfCode there was a need to group an iterable by a certain field in the data structure. I found out, that was a function called groupby in the built-in itertools library that can be used for it.

In …

Continue reading

Pieces of Py #3 Clean up data from csv and save to json in a simple way with pandas

Posted on Mon 05 August 2019 in Python • Tagged with Python, Pieces of Py, Pandas, CSV, JSON • 4 min read

At work I once had to take a csv file that was exported from a large list in SharePoint, clean it up a bit and export it to a JSON format for importing in to a data layer. The csv file contained all columns in the SharePoint list, which was …

Continue reading

Pieces of Py #2: Use a dictionary instead of multiple if-statements

Posted on Thu 01 August 2019 in Python • Tagged with Python, Pieces of Py, Dictionary, Lambda, Functools • 4 min read

One thing I learned during my first #100DaysOfCode was to use a dict instead of numerous if-statements. In my opinion it can make the code much more readable among other things. Here I'll try to make an example where this concept could fit in.

In this example we create a …

Continue reading

Pieces of Py #1: Decorator with arguments

Posted on Tue 09 July 2019 in Python • Tagged with Python, Pieces of Py, Decorator • 3 min read

This post is a simple example which explains how to create a decorator function that accepts and uses argument(s). A decorator that would accept an argument could look like this:

def my_decorated_function(input):
    return input

A simple scenario could be that you would like to print something …

Continue reading