Skip to content

Commit 88747d4

Browse files
authored
Update I Best Practices.py
1 parent 2b2cd05 commit 88747d4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Writing Functions in Python/I Best Practices.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,25 @@ def median(values):
177177
178178
**************************************************************************************************************************************************************"""
179179
## Mutable or immutable?
180+
181+
"""----What do you expect the values of d and s to be after the function is called?"""
182+
183+
def store_lower(_dict, _string):
184+
"""Add a mapping between `_string` and a lowercased version of `_string` to `_dict`
185+
186+
Args:
187+
_dict (dict): The dictionary to update.
188+
_string (str): The string to add.
189+
"""
190+
orig_string = _string
191+
_string = _string.lower()
192+
_dict[orig_string] = _string
193+
194+
d = {}
195+
s = 'Hello'
196+
197+
store_lower(d, s)
198+
199+
# d = {'Hello': 'hello'}, s = 'Hello'
200+
"""!!!
201+
Dictionaries are mutable objects in Python, so the function can directly change it"""

0 commit comments

Comments
 (0)