Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
merged_multiplies = []
i = 0
while i < len(chunks):
if i + 1 < len(chunks) and chunks[i + 1] == "*":
multiplied_elements = chunks[i:i + 3:2]
i += 3
while i < len(chunks) and chunks[i] == "*":
multiplied_elements.append(chunks[i + 1])
i += 2
merged_multiplies.append(
MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
else:
merged_multiplies.append(chunks[i])
i += 1
return MeterArithmeticGroup(
[x if isinstance(x, MeterArithmeticGroup)
else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
)
else:
return MeterArithmeticGroup([int(input_string)], None)
merged_multiplies = []
i = 0
while i < len(chunks):
if i + 1 < len(chunks) and chunks[i + 1] == "*":
multiplied_elements = chunks[i:i + 3:2]
i += 3
while i < len(chunks) and chunks[i] == "*":
multiplied_elements.append(chunks[i + 1])
i += 2
merged_multiplies.append(
MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
else:
merged_multiplies.append(chunks[i])
i += 1
return MeterArithmeticGroup(
[x if isinstance(x, MeterArithmeticGroup)
else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
)
else:
return MeterArithmeticGroup([int(input_string)], None)
i = 0
while i < len(chunks):
if i + 1 < len(chunks) and chunks[i + 1] == "*":
multiplied_elements = chunks[i:i + 3:2]
i += 3
while i < len(chunks) and chunks[i] == "*":
multiplied_elements.append(chunks[i + 1])
i += 2
merged_multiplies.append(
MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
else:
merged_multiplies.append(chunks[i])
i += 1
return MeterArithmeticGroup(
[x if isinstance(x, MeterArithmeticGroup)
else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
)
else:
return MeterArithmeticGroup([int(input_string)], None)
chunks.append(current_chunk)
if paren_level > 0:
raise ValueError("Encountered unmatched open-parenthesis.")
merged_multiplies = []
i = 0
while i < len(chunks):
if i + 1 < len(chunks) and chunks[i + 1] == "*":
multiplied_elements = chunks[i:i + 3:2]
i += 3
while i < len(chunks) and chunks[i] == "*":
multiplied_elements.append(chunks[i + 1])
i += 2
merged_multiplies.append(
MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
else:
merged_multiplies.append(chunks[i])
i += 1
return MeterArithmeticGroup(
[x if isinstance(x, MeterArithmeticGroup)
else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
)
else:
return MeterArithmeticGroup([int(input_string)], None)
def from_string(cls, input_string: str, break_up_large_numbers: bool = False) -> 'MetricStructure':
"""
Creates a MetricStructure from an appropriately formatted input string. This is the simplest way of creating
complex nested structures. For example, "3 * 2 + 5 + (2 + 3)" renders to
`MetricStructure(MetricStructure(2, 2, 2), 5, MetricStructure(2, 3))`.
:param input_string: input string consisting of integers, plus signs, multiplication signs, and parentheses
:param break_up_large_numbers: see :class:`MetricStructure`
"""
return MeterArithmeticGroup.parse(input_string).to_metric_structure(break_up_large_numbers)
multiplied_elements = chunks[i:i + 3:2]
i += 3
while i < len(chunks) and chunks[i] == "*":
multiplied_elements.append(chunks[i + 1])
i += 2
merged_multiplies.append(
MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
else:
merged_multiplies.append(chunks[i])
i += 1
return MeterArithmeticGroup(
[x if isinstance(x, MeterArithmeticGroup)
else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
)
else:
return MeterArithmeticGroup([int(input_string)], None)