Skip to content

Instantly share code, notes, and snippets.

@taddeimania
taddeimania / chaos.py
Last active January 7, 2022 22:49
Proposal for Maybe type in python (True OR False)
import ast
import random
class MaybeType(type):
def __repr__(cls):
return str(bool(random.randint(0, 1)))
def __nonzero__(cls):
return ast.literal_eval(repr(cls))
# Sort a list of dictionary objects by a key - case sensitive
from operator import itemgetter
mylist = sorted(mylist, key=itemgetter('name'))
# Sort a list of dictionary objects by a key - case insensitive
mylist = sorted(mylist, key=lambda k: k['name'].lower())