Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tuples = [(1, 4), (2, 5), (3, 6), (1, 6), (0, 7), (3, 7), (0, 8), (2, 8), (5, 9), (4, 9)]
- starting_tuple = [e for e in tuples if e[0] == 0][0]
- ## note: 'starting_tuple' could be either (0, 7) or (0, 8), starting direction doesn't matter
- order = [starting_tuple[0], starting_tuple[1]]
- ## order will always start from point 0
- idx = tuples.index(starting_tuple)
- ## index of the starting tuple
- def findNext():
- global idx
- for i, e in enumerate(tuples):
- if order[-1] in e and i != idx:
- ind = e.index(order[-1])
- c = 0 if ind == 1 else 1
- order.append(e[c])
- idx = tuples.index(e)
- for i in range(len(tuples)/2):
- findNext()
- print order
Add Comment
Please, Sign In to add comment