Advertisement
phr3ncj

scramblearg.py

Sep 19th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. #      scramblearg.py
  2. #      example: python scramble.py a,b,c
  3. #
  4. #      Copyleft 2013 phra <phra@localhost>
  5. #
  6. #      This program is free software; you can redistribute it and/or modify
  7. #      it under the terms of the GNU General Public License as published by
  8. #      the Free Software Foundation; either version 2 of the License, or
  9. #      (at your option) any later version.
  10. #
  11. #      This program is distributed in the hope that it will be useful,
  12. #      but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #      GNU General Public License for more details.
  15. #
  16. #      You should have received a copy of the GNU General Public License
  17. #      along with this program; if not, write to the Free Software
  18. #      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. #      MA 02110-1301, USA.
  20. #
  21.  
  22.  
  23. import random
  24. from sys import argv
  25.  
  26. def scramble(some_list):
  27.     randomized_list = some_list[:]
  28.     while True:
  29.         random.shuffle(randomized_list)
  30.         for a, b in zip(some_list, randomized_list):
  31.             if a == b:
  32.                 break
  33.         else:
  34.             return randomized_list
  35.  
  36. arg = argv[1].split(',')
  37. arg1 = scramble(arg)
  38. print 'SCRAMBLE:'
  39. for i in range(len(arg)):
  40.         print '{:} \t <==> \t {:}'.format(arg1[i], arg[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement