I have a list comprehension and want to store the results in a set. But, the list is unhashable and therefore can't be stored in a set.
Is there some way to do a tuple comprehension instead?
I have a list comprehension and want to store the results in a set. But, the list is unhashable and therefore can't be stored in a set.
Is there some way to do a tuple comprehension instead?
I came up with the answer in the process of asking the question, so I figured I'd post it with my answer and help the next person to search for a solution. I couldn't find anything about a tuple comprehension, but you can just cast a list to a tuple and store that in the set. Like so:
wave = set()
for srces in itertools.combinations(games, self.size):
wave.add(tuple([(book, 0) for book in srces]))