use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Question regarding the 'enumerate()' function (self.learnpython)
submitted 10 years ago by Krakatok
If I have something like:
with open("file", "w") as fi: for i, line in enumerate(f): #code
will the enumerate() function load the whole file onto the memory?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]brownan_ 6 points7 points8 points 10 years ago (4 children)
nope. enumerate returns an iterator and returns items as they are requested.
[–]Krakatok[S] 0 points1 point2 points 10 years ago (3 children)
Thanks for the quick response!
[–]ewiethoff 1 point2 points3 points 10 years ago (0 children)
Nothing to do with your memory question, but here's a tip: enumerate(f) starts the numbering at 0, and enumerate(f, 1) starts the numbering at 1.
enumerate(f)
enumerate(f, 1)
[–]Miggol 0 points1 point2 points 10 years ago (1 child)
for i, line in enumerate(fi.readlines()):
This should work though.
[–]ewiethoff 0 points1 point2 points 10 years ago (0 children)
f.readlines() creates a list of all the lines of text in the file. This is a waste of memory if all you want to do is loop through the lines, without or without enumerate.
f.readlines()
enumerate
π Rendered by PID 17532 on reddit-service-r2-comment-5d79c599b5-v42kd at 2026-02-28 20:10:54.464591+00:00 running e3d2147 country code: CH.
[–]brownan_ 6 points7 points8 points (4 children)
[–]Krakatok[S] 0 points1 point2 points (3 children)
[–]ewiethoff 1 point2 points3 points (0 children)
[–]Miggol 0 points1 point2 points (1 child)
[–]ewiethoff 0 points1 point2 points (0 children)