Guest User

Untitled

a guest
Apr 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import random
  2. d = {'b': ['bob', 'bun', 'bom'], 'd': ['dob', 'don'], 'm': ['mox']}
  3.  
  4. print(d)
  5. seq = []
  6. current = 'bob'
  7. seq.append(current)
  8. d[current[:1]].remove(current)
  9. while current[-1:] in d and d[current[-1:]]:
  10. next_ = random.choice(d[current[-1:]])
  11. current = next_
  12. seq.append(current)
  13. d[current[:1]].remove(current)
  14.  
  15. print(d)
  16. print(seq)
  17.  
  18. {'b': ['bob', 'bun', 'bom'], 'd': ['dob', 'don'], 'm': ['mox']}
  19. {'b': ['bun'], 'd': ['dob', 'don'], 'm': []}
  20. ['bob', 'bom', 'mox']
Add Comment
Please, Sign In to add comment