Merge the Tools!

  • + 9 comments

    Sorry, but I couldn't get it. :(

    I don't get the idea of the three iter(s) refering to the same position in s (or do they?). They should refer to different positions in order to give the desired output.

    You say

    zip(*[iter(s)]*3)=zip(iter(s),iter(s),iter(s))
    

    which is not true. The code (where s='abcdefghi'):

    for part in zip(iter(s),iter(s),iter(s)):
        print(part)
    

    gives output:

    ('a', 'a', 'a')
    ('b', 'b', 'b')
    ('c', 'c', 'c')
    ('d', 'd', 'd')
    ('e', 'e', 'e')
    ('f', 'f', 'f')
    ('g', 'g', 'g')
    ('h', 'h', 'h')
    ('i', 'i', 'i')
    

    This output makes sense because each iter(s) refers to the same position in s for each iteration of the for loop.

    Could you please clear my doubt?