Hacker Newsnew | past | comments | ask | show | jobs | submit | aromaticrose's commentslogin

Maybe it's just too early in the morning for me or I don't know enough about Python, but why would the OPs code snippet keep the list in memory, and why is yours an improvement?

Also, is this something you could handwave because of Python's garbage collection, or is that not going to help in this case?


The OP's version is creating the list, then processing it.

The second version is an generator; it skips the 'creating the list' part.


Ohhhhh. The coffee's kicked in. Thanks for explaining. To recap, a list comprehension:

1. Creates a new, duplicate list containing every record in housing_records

2. Loops through the new list

3. Applies f() to each element and updates the new list as it loops

4. Sum() sums all the elements in the list by accessing each element and adding it to a total

Note: All returned values of f() are stored in memory at the end of step 3. This is a waste.

A generator:

1. Creates a generator object that contains nothing but acts like a list

2. When sum() accesses an element in the generator object, the generator object applies f() to the element in housing_list and returns the value

3. Sum() is therefore able to sum all the elements by "accessing" each element and adding it to a total

Note: Only one result of f() is stored in memory at any given time. Much better.


GrapheneOS is under active development and has interesting privacy and security features.

https://grapheneos.org/

https://grapheneos.org/features


I daily drive graphene. It's very good and I haven't had any issues with it. I think the security/privacy claims are somewhat overstated but it's definitely better than stock and gives you a lot of freedom in terms of how you mitigate advance of the Google empire.


I'd be interested to hear more about the security/privacy overstatements.


It depends on your threat model. If I'm trying to avoid Google-controlled hardware or firmware, it's bad. If I simply assume that the software or hardware is compromised, I have no escape from tracking, unlike with hardware kill switches.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: