-1
def make(node):    # takes some input
  for reg_names in reg.names # dont worry about reg_names and reg.names
   if reg.size > 0:    #reg.size is an inbuilt function
    found_dict = {}   # first dictionary
    found_dict['reg.name'] = 'reg.size' # i want to save the name of the register : size of the register in the format name : size
   else:
    not_found_dict = {}   
    not_found_dict['reg.name'] = 'reg.size' #again, i want to save the name of the register : size of the register in the format name : size
return found_dict, not_found_dict

Ok, so can you tell me whether from the for loop above, if the constructs for creating the dictionaries (found_dict and not_found_dict) are correct assuming reg.name and reg.size are valid constructs?

I then want to use found_dict in function_one and not_found_dict in function_two like below:

def function_one(input):   # should this input be the function 'make' as I only want found_dict?
  for name, size in found_dict.items():  #just for the names in found_dict
    name_pulled = found_dict['reg.name'] # save the names temporarily to name_pulled using the key reg.name of found_dict
    final_names[] = final_names.append(name_pulled) #save names from name_pulled into the list final_names and append them through the for loop. will this work?

def function_two(input): # i need not_found_dict so what should this input be?
  for name, size in not_found_dict.items(): #using the names in not_found_dict
  discard_name_pulled = not_found_dict['reg.name'] # save the names temporarily to discard_name_pulled using on the 'reg.name' from not_found_dict which is essentially the key to the dict
  not_used_names[] = not_used_names.append(discard_name_pulled) # in the same way in function_one, save the names to the list not_used_names and append them through the for loop. Will this construct work?

Main question is, since def make is returning two dictionaries (found_dict and not_found_dict) how do I correctly input found_dict in function_one and not_found_dict in function_two?

zubinp
  • 1
  • 2
  • Well, does it work when you try? If not, what happens? – Daniel Roseman Jul 22 '16 at 18:16
  • unfortunately i am working in an environment that does not have an intrepretor. So i need to ensure valid constructs are made. My biggest question is, how to use only one return (found_dict) from def make into function_one and the other return (not_found_dict) from def make into function_two? – zubinp Jul 22 '16 at 18:18

1 Answers1

0

First of all in your first section in the for loop every time you do :found_dict = {} or not_found_dict = {} you are clearing the contents of the dictionary. I'm not sure if this is what you want.

Second if you want to return more than one thing from a function you could always return them as an array or a tuple, something like this:

return [found_dict, not_found_dict]

Look at this question for more information.

After you return your array or tuple you can then store it in another variable like this:

result=make(inputVariable)

this will let you use each element as you want.

result[0]
result[1]

you can input them into the functions you want like this:

def function_one(inputParameter, found_dict):
    #code ....

def function_one(inputParameter, not_found_dict):
    #code ....

function_one(inputVariable, result[0])
function_two(inputVariable, result[1])
Community
  • 1
  • 1
Buzz
  • 1,751
  • 20
  • 24
  • Refrain from using `input` as it's a built-in – cwahls Jul 22 '16 at 18:21
  • There's no need to wrap the return values in a list. The original version of `return found_dict, not_found_dict` is fine; the caller can assign those to a single variable or use tuple unpacking. – Daniel Roseman Jul 22 '16 at 18:23