Skip to content

Instantly share code, notes, and snippets.

View Ad115's full-sized avatar

Andrés García García Ad115

View GitHub Profile
@Ad115
Ad115 / logic-error.py
Created October 1, 2018 19:19
Ejemplo de un error lógico
edad = int(input("Cuántos años tienes?"))
if edad > 65:
print("Ya te jubilaste?")
if edad > 21:
print("Ya eres un adulto.")
if edad > 13:
print("Eres todo un joven adolescente.")
@Ad115
Ad115 / excepciones.py
Last active October 3, 2018 06:34
En Python es mejor pedir perdón que pedir permiso...
from turtle import Turtle
squirtle = Turtle()
def izquierda(pasos):
squirtle.left(90)
squirtle.forward(pasos)
def derecha(pasos):
squirtle.right(90)
@Ad115
Ad115 / parse_newick.py
Last active December 1, 2023 10:18
A basic parser for trees in the Newick format.
"""
A simple function `parse_newick` to parse tree structures specified in the
Newick format (NHX supported). The function allows to customize the final
representation, be it lists, dicts or a custom Tree class.
Usage
-----
```
def tree_as_dict(label, children, distance, features):
if children:
@Ad115
Ad115 / tree_utils.py
Created October 15, 2019 07:20
Generic tree traversal and recursive tree reduce algorithms for Python
"""
Generic tree utilities for Python
=================================
Trees are one of the most ubiquitous data structures. It is amazing how often we
as programmers tend to reimplement the same algorithms for different trees.
This module defines generic tree-traverse and tree-reduce algorithms that can be
used with any tree-like object such as filesystem paths, lists, nested
dictionaries, expression trees or even specialized tree classes! The only thing
@Ad115
Ad115 / tree_reduce.py
Created October 15, 2019 19:52
A generic tree reduce algorithm in Python
"""
Generic recursive tree reduce algorithm
=======================================
Trees are one of the most ubiquitous data structures. It is amazing how often we
as programmers tend to reimplement the same algorithms for different trees.
This module defines a generic tree-reduce algorithms that can be
used with any tree-like object such as filesystem paths, lists, nested
dictionaries an expression tree or even specialized tree classes! The only thing