diff options
author | Aki <please@ignore.pl> | 2022-09-03 00:36:08 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-09-03 00:36:08 +0200 |
commit | 6a5f689cf6acfc0ad99134a8e65854f8a8aa1774 (patch) | |
tree | 0b1d5ef705e278f16f8766416a06b46bab2d3c64 | |
parent | 0158e340cc103c6724e6f721dfc58558e5cba858 (diff) | |
download | szilagyi-6a5f689cf6acfc0ad99134a8e65854f8a8aa1774.zip szilagyi-6a5f689cf6acfc0ad99134a8e65854f8a8aa1774.tar.gz szilagyi-6a5f689cf6acfc0ad99134a8e65854f8a8aa1774.tar.bz2 |
Cleaned-up _dataset module a bit
-rw-r--r-- | szilagyi/_dataset/__init__.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/szilagyi/_dataset/__init__.py b/szilagyi/_dataset/__init__.py index 8ff88ae..e91251e 100644 --- a/szilagyi/_dataset/__init__.py +++ b/szilagyi/_dataset/__init__.py @@ -7,21 +7,20 @@ class Vector(complex): def __getitem__(self, index): if index == 0: return self.real - elif index == 1: + if index == 1: return self.imag - else: - raise IndexError + raise IndexError def _load_from(root): - def _read(iterable): + def _vectors(iterable): for x, y in iterable: yield Vector(float(x), float(y)) def _load(filename): - with open(filename) as fd: - reader = csv.reader(fd) - return list(_read(reader)) + with open(filename, encoding='utf-8') as fp: + reader = csv.reader(fp) + return list(_vectors(reader)) def _files(directory): for filename in os.listdir(directory): @@ -29,7 +28,10 @@ def _load_from(root): if match: yield int(match.group(1)), os.path.join(directory, filename) - return [(x, _load(y)) for x, y in sorted(_files(root), key=lambda x: x[0])] + def _first(pair): + return pair[0] + + return [(index, _load(path)) for index, path in sorted(_files(root), key=_first)] INDICES = _load_from(os.path.dirname(os.path.abspath(__file__))) |