Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from my_print import mprint
- def combinations(secuence):
- return [(i, j) for i in secuence for j in secuence if i != j]
- # Same as:
- def combinations_2(secuence):
- result = []
- for i in secuence:
- mprint('i in 1st loop: {i}')
- for j in secuence:
- mprint('\tj in 2nd loop: {j}')
- #if i != j: # not needed -_-
- result.append((i,j))
- mprint('Result:\n{result}')
- return result
- if __name__ == '__main__':
- def test():
- sec = 'abcd123'
- mprint('sec: {sec}')
- print 'Combinations version 1:\n{0}'.format(combinations(sec))
- print 'Combinations version 2:'
- combinations_2(sec)
- test()
Advertisement
Add Comment
Please, Sign In to add comment