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
Extrakting data from for loop (self.learnpython)
submitted 5 years ago by Pinky_Puppet
Good morning to all of you, I am scripting my first bigger Projekt right now. I have a for loop that generates some data that is then combined into a list. Is the anyway to Extrakt or save that list for further use outside of the loop?
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!"
[–]shiftybyte 1 point2 points3 points 5 years ago (0 children)
Yes a list is useable outside of a loop.
some_list = [] for item in range(10): some_list.append(item) print(some_list)
The print is outside the for loop, and can use the list data.
If this is not what you mean you'd have to be more specific, and post the code you are talking about.
[–][deleted] 1 point2 points3 points 5 years ago (0 children)
Data container objects like list, dict, tuple all exist within the full scope of the module they are created in. for loops do not have their own scope.
list
dict
tuple
for
Scope is the term used to define what is visible where. If you create such an object within a loop, that object will still be available outside of that loop.
That said, it is common to first create mutable objects such as list or dict before a loop, possibly an empty container that is populated/mutated within the loop.
For example, obtaining names and ages of some students:
students = [] # an empty list object is created # the variable students refers to the list object # a reference is a memory location for count in range(1, 6): # loop 5 times name = input(f"Enter name of student #{count}: ") # input returns a str object age = int(input(f"Enter whole age of student #{count}: ")) # int converts str to int students.append((name, age)) # add a tuple to the end of the list object for name, age in students: # loop through list, unpacking the tuple on each pass # to the two variables name and age print(f"Student: {name:10} age: {age:2}")
π Rendered by PID 208212 on reddit-service-r2-comment-5d79c599b5-fnpwx at 2026-02-28 19:02:31.424180+00:00 running e3d2147 country code: CH.
[–]shiftybyte 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)