Closed GaffaSnobb closed 10 months ago
Thanks for the detailed report and the repro steps. I agree this is wrong and should match python and have updated combinations
and combinations_with_replacement
to match. I'm sure there's a cleaner way than where I ended up, but it seems to work.
f I had this problem in Python I'd simply append an empty tuple so that the list would iterate once, but I'm not quite sure how to do this with whatever object
iter::combinations
is giving me.
This shouldn't matter at this point but iter::chain
would probably be the way to try to append something extra.
Thanks, mate! Appreciate the quick response!
Consider these simple Python examples:
Note that when
r
is zero the return value is not an empty list, but rather a list containing an empty tuple, meaning that the returned list will iterate once:With
iter::combinations
however, I see thatdoes not iterate. Maybe this is intended? My current use case of
iter::combinations
is to generate two different sets of combinations wherer
might be zero for either of them. I then iterate over every combination in the first set and for each of these combinations I iterate over every combination in the second set and concatenate them:Because the object (combinator?) returned by
iter::combinations
does not iterate at all ifr
is zero, the vectorbasis_states
will be empty if either of the combinations'r
value is zero. With Python'sitertools.combinations
however, if ther
value of one of the combinations is zero, thenbasis_states
will simply be equal to the combination whoser
value is non-zero.As of now I have to do an if-else and separately handle the three possible cases (both non-zero, only first non-zero, only second non-zero) which of course works, but it could be prettier : )
Is this intentional or should it be fixed? If I had this problem in Python I'd simply append an empty tuple so that the list would iterate once, but I'm not quite sure how to do this with whatever object
iter::combinations
is giving me.