I needed to check if the object is one of the following types: dict, OrderedDict, defaultdict.
assert all([dictalike(x) for x in [dict(), OrderedDict(), defaultdict()]) assert not any([dictalike(x) for x in [str(), int(), float(), ...])
I needed to check if the object is one of the following types: dict, OrderedDict, defaultdict.
assert all([dictalike(x) for x in [dict(), OrderedDict(), defaultdict()]) assert not any([dictalike(x) for x in [str(), int(), float(), ...])
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()))
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.
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!
I’ve written a simple python script which uses svgwrite module for generating chessboard of various styles in svg format.
Chcete stahovat muziku pouze tím že napíšete její název nebo pár zpívaných slov?
I recently needed a layout whose height would be automatically set to the sum of heights of inner child elements. So when there are TextInputs and the user writes more lines of text, the layout will suitably change its height. Celý příspěvek
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!