Advertisement
MrPolywhirl

ListReduce.py

Oct 8th, 2013
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from __future__ import division
  4.  
  5. import collections
  6. import sys
  7.  
  8. compare = lambda x, y: collections.Counter(x) == collections.Counter(y)
  9.  
  10. def main():
  11.     initial  = [3, 6, 5, 1, 9, 7, 2, 12, 23]
  12.     expected = [2, 4, 3, 0, 6, 5, 1,  7,  8]
  13.        
  14.     for newMin in range(len(initial)):
  15.         minIndex, minValue = 0, sys.maxint
  16.        
  17.         for i in range(len(initial)):
  18.             currValue = initial[i]
  19.             if currValue < minValue and currValue > newMin:
  20.                 minValue, minIndex = currValue, i
  21.        
  22.         initial[minIndex] = newMin
  23.        
  24.     print compare(initial, expected)
  25.  
  26. if __name__ == '__main__':
  27.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement