Aug-31-2020, 06:45 AM
In the generator comprehension,
It's slightly easier to show the translation for a list comprehension since you're not having to
For a list comprehension of the form
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