List comprehension behavior in python
问题 I am working with Codeskulptor on a rock collision problem. I want to check collisions between rocks and my rocks are in a list. I came up with the solution to build a list of combinations and then check for collision. I do not have itertools available. My combination list was created like this: def combinations(items): n_items = [(n,item) for n,item in enumerate(items)] return [(item,item2) for n,item in n_items for m,item2 in n_items[n:] if n != m] letters = ['A','B','C','D'] print