Skip to content

Commit

Permalink
optimize _expand_named_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Luffbee committed Dec 2, 2021
1 parent b7feb75 commit 71ee32b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,11 @@ def _expand_named_fields(self, named_fields):
result = {}
for field, value in named_fields.items():
# split 'aaa[bbb][ccc]...' into 'aaa' and '[bbb][ccc]...'
basename, subkeys = re.match(r'([^\[]+)(.*)', field).groups()
n = field.find('[')
if n == -1:
basename, subkeys = field, ''
else:
basename, subkeys = field[:n], field[n:]

# create nested dictionaries {'aaa': {'bbb': {'ccc': ...}}}
d = result
Expand Down

0 comments on commit 71ee32b

Please sign in to comment.