This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: permutations len issue
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1, Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: DSblizzard, amaury.forgeotdarc
Priority: normal Keywords:

Created on 2013-10-28 17:16 by DSblizzard, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg201556 - (view) Author: Evgeny Luttsev (DSblizzard) Date: 2013-10-28 17:16
Code:
n = 2
perms = permutations(range(n), n)
if list(perms) == [(0, 1), (1, 0)]:
	print("==")
	print("len(list(perms)):", len(list(perms)))

Result:
==
len(list(perms)): 0 # SHOULD BE 2
msg201557 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013-10-28 17:22
permutations() returns a generator.
If you consume it with list(), the second time will return the empty list.

Use list(permutations(...)) if you plan to use the result multiple times.
History
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63622
2013-10-28 17:22:39amaury.forgeotdarcsetstatus: open -> closed

nosy: + amaury.forgeotdarc
messages: + msg201557

resolution: not a bug
2013-10-28 17:16:58DSblizzardcreate