Skip to content

Commit 787f4ca

Browse files
Apply suggestions from code review
Co-authored-by: Copilot <[email protected]>
1 parent f721b0f commit 787f4ca

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

python-optional-arguments/optional_params.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ def add_item(item_name, quantity, shopping_list=None):
3535
def add_items_args(shopping_list, *item_names):
3636
"""Add any number of item names with default quantity 1 using *args."""
3737
for item_name in item_names:
38-
shopping_list[item_name] = 1
38+
if item_name in shopping_list:
39+
shopping_list[item_name] += 1
40+
else:
41+
shopping_list[item_name] = 1
3942
return shopping_list
4043

4144

4245
def add_items_kwargs(shopping_list, **things_to_buy):
4346
"""Add any number of items with explicit quantities using **kwargs."""
4447
for item_name, quantity in things_to_buy.items():
45-
shopping_list[item_name] = quantity
48+
if item_name in shopping_list:
49+
shopping_list[item_name] += quantity
50+
else:
51+
shopping_list[item_name] = quantity
4652
return shopping_list
4753

4854

0 commit comments

Comments
 (0)