ismaelvc

combinations.py

May 12th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. from my_print import mprint
  2.  
  3. def combinations(secuence):
  4.     return [(i, j) for i in secuence for j in secuence if i != j]
  5.  
  6.  
  7. # Same as:
  8. def combinations_2(secuence):
  9.     result = []
  10.     for i in secuence:
  11.         mprint('i in 1st loop: {i}')
  12.         for j in secuence:
  13.             mprint('\tj in 2nd loop: {j}')
  14.         #if i != j:     # not needed -_-
  15.         result.append((i,j))
  16.     mprint('Result:\n{result}')
  17.     return result
  18.  
  19. if __name__ == '__main__':
  20.     def test():    
  21.         sec = 'abcd123'
  22.         mprint('sec: {sec}')
  23.         print 'Combinations version 1:\n{0}'.format(combinations(sec))
  24.         print 'Combinations version 2:'
  25.         combinations_2(sec)
  26.  
  27.     test()
Advertisement
Add Comment
Please, Sign In to add comment