1
Good morning! I’m trying to create a dictionary where it has some keys inside other keys, and each key contains more than one item. I have looked in several places but I can’t find anything about it. I may not be doing a correct search. If anyone can help me, I’d really appreciate it.
I’m doing it this way:
g = {"V": {"S", "X", "Y"},
"T": {"a", "b"},
"P": {"S": "aXa, bXb, ø", "X": "a, b, Y", "Y": "ø"},
"S": {"S"}
}
Thus, the "P" key contains several other keys, which are "S", "X" and "Y". But in this way, the items within these keys are being unique, stored in a single index. Like: "Axa, bXb, ø" are within the same index. I want to divide them so that each item is in a single position. I don’t know if I’ve been very clear, but if anyone has an idea, it would be very helpful.
"I don’t know if I was too clear", was not. You literally wrote in the code,
"S": "aXa, bXb, ø"
, that all these values are the same string and therefore makes up the same value. What was the expected result of this operation?– Woss
Welcome to Stack Overflow! Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English.
– Maniero
Hello, Woss. Yes, I only put in the code because it’s for a job at the School of Formal Languages and Automata. I’m developing a code for simplifying context-free grammar. And in that case, I need to be able to read item by item inside each key. The way I put it I know that the values are in the same string, what I need is for each value to stay in a string in order to manipulate this data. Putting several values inside the same key in a dictionary, which I’m not getting. I’ve tried to put each value inside a quote but it doesn’t work.
– William Borges