From daff0c419767874e7d1ea15885554aa98772a57e Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Tue, 18 Feb 2020 09:41:29 +0000 Subject: [PATCH] injectivitylemma.py: use namedtuple for clarity, and switch to Python 3. Signed-off-by: Daira Hopwood --- injectivitylemma.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/injectivitylemma.py b/injectivitylemma.py index 14439ed..0414333 100755 --- a/injectivitylemma.py +++ b/injectivitylemma.py @@ -1,16 +1,19 @@ -#!/usr/bin/python +#!/usr/bin/python3 from itertools import product +from collections import namedtuple + +cd_pair = namedtuple('cd_pair', ['c', 'd']) def c_d(): - yield (-1, 0) - yield ( 1, 0) - yield ( 0, -1) - yield ( 0, 1) + yield cd_pair(-1, 0) + yield cd_pair( 1, 0) + yield cd_pair( 0, -1) + yield cd_pair( 0, 1) def sums_mod4(cd): - return ((2**(k+1) + sum([cd[j][0] * (2**j) for j in range(k)])) % 4, - (2**(k+1) + sum([cd[j][1] * (2**j) for j in range(k)])) % 4) + return ((2**(k+1) + sum([cd[j].c * (2**j) for j in range(k)])) % 4, + (2**(k+1) + sum([cd[j].d * (2**j) for j in range(k)])) % 4) for k in (1, 2): M_k = [list(s) for s in product(c_d(), repeat=k)]