I am trying to group cards of the same suit (color) and rank inside generators and store these generators inside the list comprehension.
The solution I came up with does this, except for the fact that all the generators contain exactly the same cards. Any idea why?
Here is the code
deck=range(52)
gens=[(i for i in deck if i%13==v) for v in range(13)]
Based on this, I would expect, for example:
gens[1].next()
1
gens[1].next()
14
gens[10].next()
10
gens[10].next()
23
But instead I get
gens[1].next()
12
gens[1].next()
25
gens[1].next()
38
And all the generators in the list return the same results.
source
share