From a5924b4642bd55d882bbec480f0a99534a69ed7b Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 11 May 2017 22:32:55 -0700 Subject: [PATCH] I don't know how I forgot about dict(zip()) --- etiquette/helpers.py | 13 ------------- etiquette/objects.py | 10 +++++----- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/etiquette/helpers.py b/etiquette/helpers.py index 9b2fd1e..0cf4c0b 100644 --- a/etiquette/helpers.py +++ b/etiquette/helpers.py @@ -247,19 +247,6 @@ def now(timestamp=True): return n.timestamp() return n -def parallel_to_dict(keys, values): - ''' - Given two parallel sequences, return a dictionary where the keys are - elements of `keys` and their values are the element of `values` with the - same index. - - ['test', 'toast'], - ['hello', 'world'] - -> - {'test': 'hello', 'toast': 'world'} - ''' - return {keys[index]: value for (index, value) in enumerate(values)} - def read_filebytes(filepath, range_min, range_max, chunk_size=2 ** 20): ''' Yield chunks of bytes from the file between the endpoints. diff --git a/etiquette/objects.py b/etiquette/objects.py index 689b966..07fc809 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -221,7 +221,7 @@ class Album(ObjectBase, GroupableMixin): def __init__(self, photodb, db_row): super().__init__(photodb) if isinstance(db_row, (list, tuple)): - db_row = helpers.parallel_to_dict(constants.SQL_ALBUM_COLUMNS, db_row) + db_row = dict(zip(constants.SQL_ALBUM_COLUMNS, db_row)) self.id = db_row['id'] self.title = db_row['title'] self.description = db_row['description'] @@ -426,7 +426,7 @@ class Bookmark(ObjectBase): def __init__(self, photodb, db_row): super().__init__(photodb) if isinstance(db_row, (list, tuple)): - db_row = helpers.parallel_to_dict(constants.SQL_BOOKMARK_COLUMNS, db_row) + db_row = dict(zip(constants.SQL_BOOKMARK_COLUMNS, db_row)) self.id = db_row['id'] self.title = db_row['title'] @@ -473,7 +473,7 @@ class Photo(ObjectBase): def __init__(self, photodb, db_row): super().__init__(photodb) if isinstance(db_row, (list, tuple)): - db_row = helpers.parallel_to_dict(constants.SQL_PHOTO_COLUMNS, db_row) + db_row = dict(zip(constants.SQL_PHOTO_COLUMNS, db_row)) self.real_filepath = helpers.normalize_filepath(db_row['filepath'], allowed=':\\/') self.real_path = pathclass.Path(self.real_filepath) @@ -949,7 +949,7 @@ class Tag(ObjectBase, GroupableMixin): def __init__(self, photodb, db_row): super().__init__(photodb) if isinstance(db_row, (list, tuple)): - db_row = helpers.parallel_to_dict(constants.SQL_TAG_COLUMNS, db_row) + db_row = dict(zip(constants.SQL_TAG_COLUMNS, db_row)) self.id = db_row['id'] self.name = db_row['name'] self.group_getter = self.photodb.get_tag @@ -1147,7 +1147,7 @@ class User(ObjectBase): def __init__(self, photodb, db_row): super().__init__(photodb) if isinstance(db_row, (list, tuple)): - db_row = helpers.parallel_to_dict(constants.SQL_USER_COLUMNS, db_row) + db_row = dict(zip(constants.SQL_USER_COLUMNS, db_row)) self.id = db_row['id'] self.username = db_row['username'] self.created = db_row['created']