Skip to content

Conversation

@lumbric
Copy link
Contributor

@lumbric lumbric commented Nov 30, 2018

The current version of unzip() works only if the inner sequence is
finite, but in Python 3 zip() can be used. See also comment in #239.

The current version of unzip() works only if the inner sequence is
finite, but in Python 3 zip() can be used. See also comment in pytoolz#239.
@eriknw
Copy link
Member

eriknw commented Jun 22, 2019

Aha, right you are. Thanks, @lumbric! I performed the following experiment to convince myself:

In [1]: from toolz.sandbox import unzip                                                                      

In [2]: import itertools                                                                                     

In [3]: seq = ((i, i+10, i+20) for i in itertools.count())                                                   

In [4]: next(seq)                                                                                            
Out[4]: (0, 10, 20)

In [5]: next(seq)                                                                                            
Out[5]: (1, 11, 21)

In [6]: next(seq)                                                                                            
Out[6]: (2, 12, 22)

In [7]: a, b, c = unzip(seq)                                                                                 

In [8]: next(a)                                                                                              
Out[8]: 3

In [9]: next(a)                                                                                              
Out[9]: 4

In [10]: next(b)                                                                                             
Out[10]: 13

In [11]: next(b)                                                                                             
Out[11]: 14

In [12]: seq2 = zip(a, b, c)                                                                                 

In [13]: next(seq2)                                                                                          
Out[13]: (5, 15, 23)

In [14]: next(seq2)                                                                                          
Out[14]: (6, 16, 24)

In [15]: next(seq2)                                                                                          
Out[15]: (7, 17, 25)

I also tried unzip([itertools.count(i) for i in range(5)]), which, as now expected, exploded memory usage.

@eriknw eriknw merged commit 4e0e819 into pytoolz:master Jun 22, 2019
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

Successfully merging this pull request may close these issues.

2 participants