Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7459073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:57:06+00:00 2026-05-29T13:57:06+00:00

UPDATE: Sorry I was wrong with my assumption of the problem. Its due to

  • 0

UPDATE: Sorry I was wrong with my assumption of the problem. Its due to me trying to make the function parallel and have multiple proceses change the same dictionary. How can I design my function so it allows for this? If I have to send the dictionary(in this case) then it’ll keep overwriting itself and can’t span over all the cores. I’m happy to redesign the function but not sure how i can do it and still spread it over multiple cores.

To simplify, I basically have something like the following:

list = [1,2,3,10]
dictionary = {}
for x in list:
    for xx in range(100):
        for xxx in range(100):
            dictionary[x]=xx*xxx

This works, but when I wrap the for loop in a function, I get:
NameError: global name ‘dictionary’ is not defined

def test(x):
        for xx in range(100):
            for xxx in range(100):
                dictionary[x]=xx*xxx

I know this has something to do with the namespace but I don’t want to send variables to the function in this case because I think it’ll overwrite the variable dictionary. How can I reference the dictionary variable while in the function? The reason I ask is I want to create a process that spans multiple cpu’s, so I don’t want to declare the variables in each function.

I’m using functions but if I need to use classes or there’s another way to get around this then please me know and I’ll rethink my approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:57:08+00:00Added an answer on May 29, 2026 at 1:57 pm

    Try again:

    lst = [1,2,3,10]
    dictionary = {}
    def test(x):
        for xx in range(100):
            for xxx in range(100):
                dictionary[x]=xx*xxx
    
    for x in lst:
        test(x) 
    

    You only get a NameError when a name is not defined. It has nothing to do with scopes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Updated, sorry about the change but now to the real problem] I cannot include
i have the following jquery code: $(document).ready(function() { $('.restrictiveOptions input[type!=checkbox], .restrictiveOptions select').change(function() { //
Is there any way to do this? Update: Sorry, I should have included more
(Sorry for my mistakes in spelling) I have a problem in the combination of
sorry if the question is too dull but I have been trying to understand
update: I know there is no one best way to do everything. Sorry for
Sorry for the double post, I will update this question if I can't get
Update: I add a while to get the remain data, problem solved. thanks you
Update: I am sorry i pasted in list.xml twice by mistake, my question is
I'm trying to make a div containing text scroll up. I've searched tutorials and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.