Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Last active March 17, 2021 21:58
Show Gist options
  • Save MartinThoma/dc8ed53b8f48a708764371621eb27ab0 to your computer and use it in GitHub Desktop.
Save MartinThoma/dc8ed53b8f48a708764371621eb27ab0 to your computer and use it in GitHub Desktop.
# Old style, before Python 3.7
from collections import namedtuple
attribute_names = ["longitude", "latitude", "address"]
Position = namedtuple("Position", attribute_names, defaults=(None,))
# Python 3.7 and later:
from typing import NamedTuple
class Position(NamedTuple):
longitude: int
latitude: int
address: int
# Both are used in the same way
pos1 = Position(49.0127913, 8.4231381, "Parkstraße 17")
pos2 = Position(42.1238762, 9.1649964)
def get_distance(p1: Position, p2: Position) -> float:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment