[issue27678] itertools.permutations/.combinations should have len

2016-08-04 Thread R. David Murray

R. David Murray added the comment:

It may be time to create a faq entry about len and itertools; it seems to be a 
very popular idea. For various reasons (documented in several issues in this 
tracker now), we are not going to add len to the iterators in itertools.  See 
issue 24849, and in particular msg248496.

--
nosy: +r.david.murray
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27678] itertools.permutations/.combinations should have len

2016-08-04 Thread Stéphane Wirtel

Stéphane Wirtel added the comment:

__length_hint__ returns an estimated length for the object.

As you said, if the object passed-in has a length, we could use it. If not, 
then raise TypeError. But we will have two different behaviors in function of 
the parameter.

--
nosy: +matrixise

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27678] itertools.permutations/.combinations should have len

2016-08-04 Thread Claudiu Saftoiu

Claudiu Saftoiu added the comment:

Ahh, I see. In that case, if the object passed-in has a length, use that. If 
not, then raise TypeError. e.g. proposed behavior:

>>> len(itertool.combinations(range(10), 2))
45
>>> len(itertool.combinations(iter(range(10)), 2))
...
TypeError: itertools.combinations underlying object has no len()

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27678] itertools.permutations/.combinations should have len

2016-08-04 Thread Xiang Zhang

Changes by Xiang Zhang :


--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27678] itertools.permutations/.combinations should have len

2016-08-04 Thread Xiang Zhang

Xiang Zhang added the comment:

You have to exhausts the iterator to get the actual length. Some iterators have 
__length_hint__ but it's not required to give the truth.

--
nosy: +xiang.zhang

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27678] itertools.permutations/.combinations should have len

2016-08-04 Thread Claudiu Saftoiu

New submission from Claudiu Saftoiu:

Right now, itertools.permutations and itertools.combinations and 
itertools.product objects don't have a `len`. 

>>> len(itertools.combinations(range(10), 5))
Traceback (most recent call last):
  File "", line 1, in 
TypeError: object of type 'itertools.combinations' has no len()

I propose that a `len` be added to them, which computes (& caches) & returns 
the length. If the underlying iterator doesn't have a length, then they can 
raise a TypeError as they do now.

--
messages: 271952
nosy: Claudiu Saftoiu
priority: normal
severity: normal
status: open
title: itertools.permutations/.combinations should have len
type: enhancement
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com