Quesiton
When trying to delete a key from a dictionary, I write:
- if 'key' in myDict:
- del myDict['key']
How-To
Use dict.pop():
For more usage of dict, please refer to "[Quick Python] 7. Dictionaries".
This is a blog to track what I had learned and share knowledge with all who can take advantage of them
>>> my_dict = {"last":"john", "first":"lee", "age":18, }
>>> my_dict.pop("last")
'john'
>>> my_dict.pop("not exist")
Traceback (most recent call last):
File "", line 1, in
KeyError: 'not exist'
>>> my_dict.pop("middle", "KC") # Second argument 'KC' is returned while the key doesn't exist
'KC'
>>> my_dict
{'age': 18, 'first': 'lee'}
Source From Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 # git clean -d -fx 方案2: 今天在服务器上 gi...
沒有留言:
張貼留言