##### What happens to a <itertools.permutations object at 0x7fe3cc66af68> after it is read?
 What happens to a after it is read? Pedroski55 Spam, spam, eggs, and spam Posts: 271 Threads: 101 Joined: Jul 2017 Reputation: Nov-29-2020, 08:14 AM I want to get all permutations of 2 vowels ```from itertools import permutations doubles = permutations (['a', 'e', 'i', 'o', 'u'],2) for i in doubles: print(i) ```This prints all the permutations. I want to save them in a list. I tried: ```perm = ('a', 'e') perm[0] gives me 'a' perm[1] gives me 'e'```Now I find, if I run: ```doubles = permutations (['a', 'e', 'i', 'o', 'u'],2) for i in doubles: print(i)```I see my permutations If I run ```for i in doubles: print(i)```again, I get nothing. No error. Nothing. Where has doubles gone? Seems it can only be read 1 time. Why is that? Read it and it is gone! This gets me what I want: ```doubles = permutations (['a', 'e', 'i', 'o', 'u'],2) perms = [] for i in doubles: print(i) perm = i[0] + i[1] perms.append(perm)``` Reply Posts: 7,605 Threads: 133 Joined: Sep 2016 Reputation: Nov-29-2020, 08:24 AM once you iterate over it, the `itertools.permutations` object is exhausted and there is nothing to return on second attempt to use/iterate over it ```from itertools import permutations doubles = permutations(['a', 'e', 'i', 'o', 'u'], 2) print(type(doubles)) doubles = list(permutations(['a', 'e', 'i', 'o', 'u'], 2)) print(type(doubles))`````````Output: =3.6.0 Almost dead, but too lazy to die: https://sourceserver.info All humans together. We don't need politicians! Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Making lists using itertools and eliminating duplicates. mike3891 2 677 Oct-26-2020, 05:39 PM Last Post: bowlofred Python3 itertools.groupby printing the key august 1 724 Aug-17-2020, 05:46 AM Last Post: bowlofred Generate Cartesian Products with Itertools Incrementally CoderMan 2 656 Jun-04-2020, 04:51 PM Last Post: CoderMan [split] AttributeError: 'str' object has no attribute 'read' laxmipython 2 2,202 Feb-14-2020, 01:15 PM Last Post: laxmipython itertools.zip_shortest() fo unequal iterators Skaperen 10 2,614 Dec-27-2019, 12:17 AM Last Post: Skaperen Permutations mikke3141 2 900 Dec-23-2019, 06:09 PM Last Post: mikke3141 can itertools compact a list removing all of some value? Skaperen 6 1,338 Sep-02-2019, 03:19 AM Last Post: Skaperen More Efficent Way of Generating Permutations/ w Rep ClassicalSoul 2 1,145 Aug-22-2019, 05:22 AM Last Post: perfringo Help with itertools jarrod0987 1 833 Jun-10-2019, 02:41 AM Last Post: Larz60+ ImportError: No module named jaraco.itertools in Python manhnt 0 1,658 Nov-08-2018, 11:41 AM Last Post: manhnt

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020