python nested dictionary comprehension in static class scope: variable not defined [duplicate]
问题 This question already has answers here : Accessing class variables from a list comprehension in the class definition (5 answers) Closed 3 days ago . I've got this code: class Chars: char_to_number = { 'a': ['1'], 'b': ['2'], 'c': ['3', '6'], 'd': ['4', '5'], } number_to_char = { number: char for char in char_to_number for number in char_to_number[char] } Now this code returns an error as such: name 'char_to_number' is not defined Now it looks like python could not parse the nested dictionary