2016-07-22 12 views
-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それぞれを使用して、2つの辞書を返すので、私を伝えることができ.sizeは有効な構文ですか?私はその後、下記のようにfunction_twoにfunction_oneとnot_found_dictでfound_dictを使用したいは、別個の機能

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? 

主な質問はデフにするために、であるが、私はfunction_oneで正しく入力found_dictどのように行う2つの辞書(found_dictとnot_found_dict)を返しますfunction_twoのnot_found_dict?

+0

まあ、それは動作しますか?そうでない場合はどうなりますか? –

+0

残念ながら私はintrepretorを持たない環境で作業しています。だから私は有効な構造が作られていることを確認する必要があります。私の最大の疑問は、def makeからfunction_oneへの戻り値(found_dict)と、def makeからの戻り値(not_found_dict)をfunction_twoに使う方法です。 – zubinp

答えて

0

最初に、あなたが行うループの最初のセクションでは:found_dict = {}またはnot_found_dict = {}は辞書の内容を消去しています。これがあなたが望むものなのかどうかは分かりません。詳細については、this question

return [found_dict, not_found_dict] 

ルック:あなたは常にこのような配列やタプル、何かとしてそれらを返すことができる機能から、複数のものを返したい場合は、2番目の

あなたの配列やタプルを返した後、あなたは、このような別の変数に格納することができます

result=make(inputVariable) 

これはあなたが望むように、各要素を使用できるようになります。

result[0] 
result[1] 

あなたはこのようにしたい機能に入力し、それらをすることができます:あなたがしようとすると、

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]) 
+0

組み込みの –

+0

が正しいので、 'input'の使用を控えてください。私はそれを修正します – Buzz

+0

リストに戻り値をラップする必要はありません。 'return found_dict、not_found_dict'の元のバージョンは問題ありません。呼び出し側はそれらを単一の変数に割り当てたり、タプルの展開を使用したりすることができます。 –

関連する問題