From 95e375f44a99c6aa48e3a67b281bb871781580c4 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 25 Jun 2015 16:34:47 +0200 Subject: [PATCH] Use dictionary comprehension in selection When doing a selection, a new context (in the form of a dictionary) is created. Instead of re-using the same dictionary re-assigning the values, now use a comprehension to avoid redundant reads. --- relational/relation.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/relational/relation.py b/relational/relation.py index 076589a..5443e34 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -106,13 +106,11 @@ class relation (object): def selection(self, expr): '''Selection, expr must be a valid boolean expression, can contain field names, constant, math operations and boolean ones.''' - attributes = {} newt = relation() newt.header = header(self.header) for i in self.content: # Fills the attributes dictionary with the values of the tuple - for j,attr in enumerate(self.header): - attributes[attr] = i[j].autocast() + attributes = {attr:i[j].autocast() for j, attr in enumerate(self.header)} try: if eval(expr, attributes):