I want to put this for loop into a comprehension. Is this even possible?
for i in range(1, 11):
result = len({tuple(walk) for (walk, distance) in dic[i] if distance == 0})
print(f'There are {result} different unique walks with length {i}')
I tried stuff like
print({tuple(walk) for i in range(1, 11) for (walk, distance) in dic[i] if distance == 0})
but this prints all walks for all i together, but i want 10 different print statements.
You were pretty close actually:
[print(f'There are {len({tuple(walk) for (walk, distance) in dic[i] if distance == 0})} different unique walks with length {i}') for i in range(1,11)]
But it's a long and ugly oneliner, in a regular for
loop it looks way better.