Sort nested dict in python – OrderedDict

Nested ordered dict sort. If you need to sort your dict or OrderedDict, this snippet may come helpfull.

from collections import OrderedDict
def ordered_dict(od, reverse=False, sort_key=None):
    """Sort nested ordered dict recursively.

    sort_key
    - sort by dict key case insensitively:
        sort_key = lambda (k, v): k.lower()
    """
    if not isinstance(od, OrderedDict):
        od = OrderedDict(od)

    res = OrderedDict()
    for k, v in sorted(od.items(), reverse=reverse, key=sort_key):
        if isinstance(v, dict):
            res[k] = ordered_dict(v)
        else:
            res[k] = v
    return res

# show-off
a = {chr(i+ord('a')+(i%2)*(ord('A')-ord('a'))): i for i in reversed(range(0,26))}
print(ordered_dict(a, reverse=True, sort_key=lambda (k,v): k.lower()))

kivent-robotic-visualiser (krv) documentation

Links

Frameworks used

The 2D robot simulation program is written in Python 3.5 and uses mainly GUI module kivy and its counterpart for game logic the kivent module.

Using kivent module complex physics, graphics, and game environment was created using only Python language the low-level parts of physics interactions are written as wrappers in Cython utilizing the cymunk – python port of 2d physics engine Chipmunk2D.

The compiling and installation of the kivy and kivent modules from source codes can be done using the playbook.yml file (using ansible-playbook is an installer program) or getting help from online forums and official pages.

Celý příspěvek

Python + Gamepad = CLI grabber + drawille = CLI stick direction visualiser

So I am creating a robot gr4dalek with a Mecanum drive. I thought omni-drive — I can drive in all directions. When on manual I need to give angle direction and speed. So gamepad. Also, keep it simple, I didn’t want to use pygame, tell me more about bloat processing.

Celý příspěvek

Microsnake vs micropython

So I am playing with the possibilities of micropython – the python interpreter in the embeded microcontroller enviroment. Using the STM32F4Discovery board.

Currently I am driving 4 character displays (HD lcd1602) with I2C controllers (ebay) via one STM’s i2c line. Creating a game of snake :“).

The source code is available on my github repo here.

Take a look and envy!

The image processing algorithm visualiser (IPAV)

Recently I have created a Python openCV „frontend“ which allows a creation of computer vision algorithms by simply writing down their comma separated names. It creates a nice square widget chain where every „step“ algorithm has its own picture and info string. Interested? Keep reading!

Celý příspěvek