Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #/home/clockworkpc/Documents/bin/swingList2.py
- # Released under a GPLv3 Licence by Clockwork PC 2011
- # www.clockworkpc.com.au
- # You are entitled to the following four freedoms:
- # Freedom 0: To run this program for any purpose
- # Freedom 1: To study how this program works and change it to make it do what you wish
- # Freedom 2: To redistribute copies so you can help your neighbour
- # Freedom 3: To distribute copies of your modified version to others
- import random
- def permissiblePair(l,f):
- # Last names must be different
- return l[l.find(" ")+1:] != f[f.find(" ")+1:]
- def main():
- leads = ['Mr Lindy', 'Mr Charleston', 'Mr Blues', 'Mr Balboa']
- follows = ['Mrs Lindy', 'Mrs Charleston', 'Mrs Blues', 'Mrs Balboa']
- # Note limitation of random.shuffle() at
- # http://docs.python.org/library/random.html#random.shuffle
- random.shuffle(follows)
- while len(leads)>0:
- if permissiblePair(leads[0],follows[0]):
- print leads[0]+ " gets to swing with " + follows[0]
- leads.pop(0)
- follows.pop(0)
- else:
- # Cycle follows
- f=follows.pop(0)
- follows.append(f)
- if __name__=="__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement