Skip to content

Instantly share code, notes, and snippets.

View langner's full-sized avatar

Karol M. Langner langner

  • Google
  • Mountain View
View GitHub Profile
@langner
langner / similar_first_author.py
Last active May 7, 2021 09:34
Python function for testing similarity between the first authors in two article author fields
def similar_first_author(author1, author2):
"""Determine whether two first authors have the same names.
Since there can be various fluctuations in first names and initials, we will
only check the first word in the author string and the first letter of the
second word. Although the second word is usually the first name, there will
be exceptions for multi-word last names, but this will be a small minority
and still passes our test. In case there is just a single word, use just that.
"""
author1 = author1.lower().decode('utf-8')
@langner
langner / prufer_code.py
Created September 21, 2015 22:13
Transformation of trees into Prufer sequence and back
"""Transformation of trees into Prufer sequence and back.
The Prufer sequence of a labeled tree is a unique seqience associated
with that tree on length n-2 where there are n vertices in the tree.
More information: https://en.wikipedia.org/wiki/Prüfer_sequence
Copyright 2015 Karol M. Langner, Google Inc.
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0
"""