mahmoudimus / mahmoudimus.com

my hacker moleskine
mahmoudimus.com/blog
2 stars 1 forks source link

n-wise iterator broken? #1

Open john-clarke opened 10 years ago

john-clarke commented 10 years ago

I came across your article about n-wise iteration which looks helpful. I tried to run it in Python 2.7 but am getting a ValueError: too many values to unpack error on the print first, second, third line. Also, I'd prefer a result that gives an additional two lists

So

for first, second, third in n_wise([0, 1, 2, 3, 4, 5, 6], 3):
    print first, second, third

would render:

0, 1, 2
1, 2, 3
2, 3, 4
3, 4, 5
4, 5, 6
5, 6, 0
6, 0, 1
mahmoudimus commented 10 years ago

@john-clarke do you have a test case that shows that this is giving too many values to unpack?

happy to update it for you.