Apr-07-2020, 04:54 PM
(This post was last modified: Apr-07-2020, 04:54 PM by deanhystad.)
This is why your original program did not work:
This is what your function does with all the extra stuff removed:
import collection x = collections.Counter(['a', 'b']) y = collections.Counter(['b', 'a']) print(x) print(y) print(x==y)
Output:Counter({'a': 1, 'b': 1})
Counter({'b': 1, 'a': 1})
True
Counter does not care about order of entries in the source collection.This is what your function does with all the extra stuff removed:
numbers = [('a','a'), ('c','a')] def find_edge(nodes, x, y): for node in nodes: if x == node[0] and y == node[1]: return True return False print(find_edge(numbers, 'a', 'c')) print(find_edge(numbers, 'c', 'a'))
Output:False
True