Python Forum
Tuple comprehension to for loop help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tuple comprehension to for loop help
#2
In the generator comprehension, hashes holds the iterator returned by the generator. In your attempt, hashes holds only one element from the iteration (one by one as you loop).

It's slightly easier to show the translation for a list comprehension since you're not having to yield.

For a list comprehension of the form
mylist = [x*2 for x in iter]
Then an unroll of it might look like:
temp_list = []
for x in iter:
    temp_list.append(x*2)
mylist = temp_list
Reply


Messages In This Thread
Tuple comprehension to for loop help - by jsuh21 - Aug-31-2020, 05:55 AM
RE: Tuple comprehension to for loop help - by bowlofred - Aug-31-2020, 06:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 1,627 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  For Loop with List Comprehension muzikman 25 10,403 Dec-18-2020, 10:45 PM
Last Post: muzikman
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 4,428 Nov-04-2020, 11:26 AM
Last Post: Aggam
  Help: list comprehension for loop with double if statement mart79 3 3,322 May-04-2020, 06:34 AM
Last Post: buran
  List comprehension. Shor for loop version dervast 1 2,146 Dec-11-2019, 12:34 PM
Last Post: perfringo
  Arrange list of tuple using loop batchenr 7 4,722 Jun-16-2019, 03:24 PM
Last Post: Abdullah
  How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? SukhmeetSingh 5 4,365 May-21-2019, 11:39 AM
Last Post: avorane

Forum Jump:

User Panel Messages

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