Feb-14-2019, 03:23 AM
(This post was last modified: Feb-14-2019, 04:09 AM by ichabod801.)
Hello all!
I have been stuck for far too long on this issue and appreciate any and all help.
I have a global dictionary and I'm trying to add to a key a value which is a list of lists.
So like this:
my_dict = { key1 : [ [name, file, withinOH], [name, file, something], ... ], key2 : [ [...], [...] ] }
I do not know how many lists there will be for a certain key in advance so I need to add them as I parse them.
As I parse my input I will get groups of items which I want to put together into a list. Each of these lists are associated with a single key. BUT they cannot all go into the same list because the groupings of items in each list is important for permissions. Thus the need for list of lists.
My plan is to search my dict for a specific key. Then search all lists inside that dict for a specific value. If found, search that list specifically for another value which should be there, if it's not, then I do not grant permissions.
I think I understand part of the problem with my code because when I create the list I want to place inside my dict of lists, it is a local variable. Somehow that forces it to override even when I use .append to my dict.
This is the code:
I have been stuck for far too long on this issue and appreciate any and all help.
I have a global dictionary and I'm trying to add to a key a value which is a list of lists.
So like this:
my_dict = { key1 : [ [name, file, withinOH], [name, file, something], ... ], key2 : [ [...], [...] ] }
I do not know how many lists there will be for a certain key in advance so I need to add them as I parse them.
As I parse my input I will get groups of items which I want to put together into a list. Each of these lists are associated with a single key. BUT they cannot all go into the same list because the groupings of items in each list is important for permissions. Thus the need for list of lists.
My plan is to search my dict for a specific key. Then search all lists inside that dict for a specific value. If found, search that list specifically for another value which should be there, if it's not, then I do not grant permissions.
I think I understand part of the problem with my code because when I create the list I want to place inside my dict of lists, it is a local variable. Somehow that forces it to override even when I use .append to my dict.
This is the code:
PA_dict = {} def addPA(paLine): entries = paLine.split("-") for entry in entries: parts = entry.split(":") n_iter = iter(parts) attributesLine = next(n_iter).strip() permissionName = next(n_iter).strip() # PR or PW attributes = attributesLine.split(";") PA_dict[permissionName] = [] my_list = [] for attribute in attributes: attribute = attribute.strip() attribute = attribute.strip("<") attribute = attribute.strip(">") attributeParts = attribute.split(",") name = attributeParts[0].strip() value = attributeParts[1].strip() # print(name + " " + value + " " + permissionName) my_list.append(value) print(my_list) #this prints out exactly what I need to go into my PA_dict list of lists PA_dict[permissionName] = my_listaugh why isn't it indenting my code