Advertisement
clockworkpc

Swingers_Party

Jun 11th, 2011
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. #!/usr/bin/python
  2. #/home/clockworkpc/Documents/bin/swingList2.py
  3.  
  4. # Released under a GPLv3 Licence by Clockwork PC 2011
  5. # www.clockworkpc.com.au
  6.  
  7. # You are entitled to the following four freedoms:
  8. # Freedom 0: To run this program for any purpose
  9. # Freedom 1: To study how this program works and change it to make it do what you wish
  10. # Freedom 2: To redistribute copies so you can help your neighbour
  11. # Freedom 3: To distribute copies of your modified version to others
  12.  
  13. import random
  14.  
  15. def permissiblePair(l,f):
  16.  # Last names must be different
  17.  return l[l.find(" ")+1:] != f[f.find(" ")+1:]
  18.  
  19. def main():
  20.  
  21.  leads = ['Mr Lindy', 'Mr Charleston', 'Mr Blues', 'Mr Balboa']
  22.  follows = ['Mrs Lindy', 'Mrs Charleston', 'Mrs Blues', 'Mrs Balboa']
  23.  
  24.  # Note limitation of random.shuffle() at
  25.  # http://docs.python.org/library/random.html#random.shuffle
  26.  
  27.  random.shuffle(follows)
  28.  
  29.  while len(leads)>0:
  30.    if permissiblePair(leads[0],follows[0]):
  31.      print leads[0]+ " gets to swing with " + follows[0]
  32.      leads.pop(0)
  33.      follows.pop(0)
  34.    else:
  35.      # Cycle follows
  36.      f=follows.pop(0)
  37.      follows.append(f)
  38.  
  39. if __name__=="__main__":
  40.  main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement