Guest User

Untitled

a guest
Jan 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. tuples = [(1, 4), (2, 5), (3, 6), (1, 6), (0, 7), (3, 7), (0, 8), (2, 8), (5, 9), (4, 9)]
  2.  
  3. starting_tuple = [e for e in tuples if e[0] == 0][0]
  4. ## note: 'starting_tuple' could be either (0, 7) or (0, 8), starting direction doesn't matter
  5.  
  6. order = [starting_tuple[0], starting_tuple[1]]
  7. ## order will always start from point 0
  8.  
  9. idx = tuples.index(starting_tuple)
  10. ## index of the starting tuple
  11.  
  12.  
  13. def findNext():
  14. global idx
  15. for i, e in enumerate(tuples):
  16. if order[-1] in e and i != idx:
  17. ind = e.index(order[-1])
  18. c = 0 if ind == 1 else 1
  19. order.append(e[c])
  20. idx = tuples.index(e)
  21.  
  22.  
  23. for i in range(len(tuples)/2):
  24. findNext()
  25.  
  26. print order
Add Comment
Please, Sign In to add comment