i got a Problem, i am creating 2 lists in a function, but i cannot work with them outside the function because it says "NameError: name "ListB" is not defined".
I need the list to create a tuple and write the tuple into a dictonary :)
#
#create 2 lists and 1 dictonary with the same length
#Example: index length is 3
def adder():
ListB = list()
ListC = list()
while True:
insert1 = input("List2 add: ")
insert2 = input("List3 add: ")
ListB.append(insert1)
ListC.append(insert2)
print("""if list length is ok, write "ok" """)
inputPerson = str(input())
if inputPerson == "ok":
break
return ListB, ListC
#run adder
adder = adder()
list2 = [] # create list2/3 with same index length
list3 = [] # to add ListB to list2 and ListC to list3
list2.append(ListB) #add ListB to list2
list3.append(ListC) #add ListC to list3
tupleList = list(zip(list2, list3)) # take element from list2 and
print(tupleList) #Test # list3 in (x, y) order
#create a dictonary with they keyword KeyX X = 0,1,2,3...n : tupleList[0]..[n]
#depending on index length, but X = tupleList[n]!!
dict_List = { \
'Key0' : tupleList[0],
'Key1' : tupleList[1],
'Key2' : tupleList[2],
}
#print out the result
print("Dict_List:", dict_List)
print("Key0", dict_List['Key0'])
print("Key1", dict_List['Key1'])
print("Key2", dict_List['Key2'])
Right now i dont know how to create a dictonary that will automatically create a new "entry" with KeyX etc.
I hope somebody will help me.