TIL: This works ```kwargs.get("tags", []) + ["my_t...
# general
d
TIL: This works
Copy code
kwargs.get("tags", []) + ["my_tag"]
This doesn't work
Copy code
kwargs["tags"] = kwargs.get("tags", []).append("my_tag")
Any reason why the later doesn't work? maybe all lists are read only and
+
creates a new list that is the combination of the two?
h
It's because
.append()
returns
None
Copy code
❯ python3
Python 3.9.6 (default, Jun 28 2021, 19:24:41)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = [1, 2].append(3)
>>> x
>>> type(x)
<class 'NoneType'>
You could also do
kwargs["tags"] = [*kwargs.get("tags", []), "my_tag"]
d
😂
🤦‍♂️ thanks
🤣 1
❤️ 1
b
I think we've all done this at some point or another. Or maybe that's just me and you @dazzling-diamond-4749. :-)
👍🏽 1
d
Here is my excuse, I never qualify my c++ hash map with
const
just so that I can use default left values (I'm terrible)