Advertisement
Guest User

function did not work correctly

a guest
Jun 30th, 2010
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. token_list = ['a', 'b', 'c']
  2.  
  3. contradictions = {
  4.     'a': set(['b']),
  5.     'b': set(['a']),
  6.     'c': set()
  7. }
  8.  
  9. def solve(tokens, contradictions):
  10.    if not tokens:
  11.       yield set()
  12.    else:
  13.       tokens = set(tokens)
  14.       t = tokens.pop()
  15.       for solution in solve(tokens - contradictions[t], contradictions):
  16.          yield solution | set([t])
  17.       if contradictions[t] & tokens:
  18.          for solution in solve(tokens, contradictions):
  19.             if contradictions[t] & solution:
  20.                yield solution
  21.  
  22. print list(solve(token_list, contradictions))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement