Skip to content

Instantly share code, notes, and snippets.

@elena-roff
elena-roff / collections_tricks.py
Created March 29, 2019 11:14
collections Tricks
from collections import defaultdict, Counter
from typing import Mapping, List
""" Most commom element with Counter.""
stuff: List = ['book', 'book', 'phone', 'book', 'phone']
cnt = Counter(stuff)
# first most common
# first element of the list and a tuple
cnt.most_common(1)[0][0]
# 'book'
@elena-roff
elena-roff / database.py
Created October 8, 2019 13:55
database setup + query runner
import psycopg2
import psycopg2.extras
from configparser import ConfigParser
import logging
logger = logging.getLogger()
logging.basicConfig(format='%(asctime)s %(message)s')
logger.setLevel(logging.DEBUG)
@elena-roff
elena-roff / setup.py
Created October 27, 2022 13:44
Making packages locally installable
# can also include requirements
# create _init_.py in the package folder
# to install: `pip install -e .`
# or with the github/lab url `pip install git+ssh://git@gitlab.com/...`
import os
import setuptools
here = os.path.abspath(os.path.dirname(__file__))