![]() |
Help with nested maps - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help with nested maps (/thread-41022.html) Pages:
1
2
|
RE: Help with nested maps - Unkovic - Nov-01-2023 (Oct-31-2023, 03:57 PM)Unkovic Wrote: The only thing I now need a help with is (nested) lists. Okay so the next question would be how could I parse homogenic map/list? list(float) -> some_name : - 3.3 - 2.3 - 3.33 ---Like here is the regex modified for array_id_pattern ^\s*(\w+\(?\w+\)?)\s*->\s*(\w+)\s*([:=])(.*)$' I wanted to check if map has optional data type after map in parentheses. but if i don't put the parentheses a 'p' letter of map would be in the matching group for it. Also as you can see, homogenic list / maps items doesn't have data types before them. We automatically know they are float. this is the function i use for processing the elements def __process_element(self, element): elem_type, number, value, line = element if elem_type == 'DICT_ITEM': tp, key, rest = value self.current_dict[key] = self.__proccess_value(tp, rest) elif elem_type == 'MAP': new_dict = {} if isinstance(self.current_dict, list): self.current_dict.append(new_dict) else: self.current_dict[value] = new_dict self.stack.append(self.current_dict) self.current_dict = new_dict elif elem_type == 'LIST': new_list = [] if isinstance(self.current_dict, list): self.current_dict.append(new_list) else: self.current_dict[value] = new_list self.stack.append(self.current_dict) self.current_dict = new_list elif elem_type == 'LIST_ITEM': tp, rest = value self.current_dict.append(self.__proccess_value(tp, rest)) elif elem_type == 'END': if self.stack: self.current_dict = self.stack.pop() |