| 1 | initial version |
To list all functions from A to B you must iterate on all points of
B^|A|. This can be achieved with itertools' 'product' function:
def all_functions(A,B):
from itertools import product
B_to_the_A = product(B,repeat=len(A))
for p in B_to_the_A:
yield dict(zip(A,p))
sage: for f in all_functions("abc",[0,1]):
....: print f
{'a': 0, 'c': 0, 'b': 0}
{'a': 0, 'c': 1, 'b': 0}
{'a': 0, 'c': 0, 'b': 1}
{'a': 0, 'c': 1, 'b': 1}
{'a': 1, 'c': 0, 'b': 0}
{'a': 1, 'c': 1, 'b': 0}
{'a': 1, 'c': 0, 'b': 1}
{'a': 1, 'c': 1, 'b': 1}
Nathann
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.