Metadata-Version: 2.1
Name: pycutils
Version: 0.0.5
Summary: A list of python utilities
Home-page: https://github.com/CangyuanLi/cutils
Author: Cangyuan Li
Author-email: everest229@gmail.com
License: UNKNOWN
Project-URL: Bug Tracker, https://github.com/CangyuanLi/cutils/issues
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown

![Tests](https://github.com/CangyuanLi/cutils/actions/workflows/tests.yml/badge.svg)

Some personal Python utilities. Only uses standard library.

# Gotchas

## Dictionaries

What is the difference between

```python
dict1 = dict(zip(["a", "b", "c"], [[]] * 3))
```
and 

```python
dict2 = {key:[] for key in ["a", "b", "c"]}
```
When you print them, both return

```python
{'a': [], 'b': [], 'c': []}
```
But try, for example, 

```python
dict1["a"].append(1)
print(dict1)
dict2["a"].append(1)
print(dict2)
```

Surprisingly, you get

```python
dict1 = {'a': [1], 'b': [1], 'c': [1]}
dict2 = {'a': [1], 'b': [], 'c': []}
```
What happened here? The empty lists in dict1 are actually the same list, so when you change one, you change all of them. You can run into the same trap if you initialize a dictionary with

```python
dict.fromkeys(["a", "b", "c"], [])
```

or if you pass in a mutable object as a default argument to a function.


