Cocode python hacks
UP | HOME

Python hacks and tricks
Python tricks

Table of Contents

1. Python is everywhere!

To be fair, I found python somewhat rudimentary. Its a hacking tool, it works great for small hacks, and its fast. Not at runtime but to actually create and do stuff, there are so many libraries out there its crazy. On the other hand, its a mess. different python version works with different modules, and its frustrating to even think about it. But maybe i shouldn't complain to much, I find it quite useful and not to say the least fun. You can get going fast. And together with LLMs it makes it even faster. I like that you are bound to use the syntax instead of some character delimiter (braces,curly braces, parenthesis and what not). I don't like exceptions, therefor a lot of my code is more functional style where you divide you requirements into Actions, Data and Computation (read Grokking simplicity) and use monads to wrap things in, there is a nice library called pymonads and i do use a lot of returning functions from functions. For example

from pymonad.maybe import Maybe,Just
def get_value_fn(mapper:dict):

    def get_value(key:str):
        try:
            return Just(mapper[key])
        except Exception as e:
            return Maybe(value=e, monoid=False)
    return get_value


my_map = {'apa': 'monkey', 'åsna': 'donkey','fisk':'fish'}

ffn = get_value_fn(my_map)
print(ffn('apa').value)
print(ffn('gurka'))

Anyway lets not do more here , lets focus on something more fun.

Pandas
Pandas overview and some hacking LLM
Pandas group
Here we dive further into pandas and start using group. And then some utilization of plots.

Author: Calle Olsen

Created: 2024-12-04 Wed 22:44

Validate