I came across this code and didn't quite really understand it:
s = { i*j for i in range(10) for j in range(10)}
print(s)
The result is {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, 28, 30, 32, 35, 36, 40, 42, 45, 48, 49, 54, 56, 63, 64, 72, 81}
As far as I'm concerned, it should iterate over the list of "i" and "j", respectively. For example, if "i" equals 0, j would go from 0 to 9, and the first elements of set s will be {0, 0, 0, ...} and the same for "i" equals 1, 2, 3,...
Could anyone help me shed more light on this?
It is equivalent to:
This iterates 100 times.
To see the combinations you might try:
Note: order is not guaranteed in a set.
Should you wish to see all of the multiples, use a list comprehension which does preserve order.