Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'batched' function looks buggy #387

Open
reachnatp opened this issue Jul 12, 2024 · 1 comment
Open

'batched' function looks buggy #387

reachnatp opened this issue Jul 12, 2024 · 1 comment

Comments

@reachnatp
Copy link

reachnatp commented Jul 12, 2024

def batched(it: Iterator, n: int):

I don't think batched function is doing what we want it to be doing. What is the intended output from it?

Test case:

import itertools
from typing import Iterator

def batched(it: Iterator, n: int):
    assert n >= 1
    for x in it:
        yield itertools.chain((x,), itertools.islice(it, n - 1))

lis = [i for i in range(10)]
n = 5
for b in batched(lis, n):
  print(b)
  for item in b:
    print(item)

Output:
<itertools.chain object at 0x793e86d9d870>
0
0
1
2
3
<itertools.chain object at 0x793e86d9e050>
1
0
1
2
3
<itertools.chain object at 0x793e86d9d540>
2
0
1
2
3
<itertools.chain object at 0x793e86d9cc10>
3
0
1
2
3
<itertools.chain object at 0x793e86d9e740>
4
0
1
2
3
<itertools.chain object at 0x793e86d9d2d0>
5
0
1
2
3
<itertools.chain object at 0x793e86d9f7c0>
6
0
1
2
3
<itertools.chain object at 0x793ebd8bf520>
7
0
1
2
3
<itertools.chain object at 0x793e86c607c0>
8
0
1
2
3
<itertools.chain object at 0x793e86c603d0>
9
0
1
2
3

@hrwleo
Copy link

hrwleo commented Jul 12, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants