Back

python - 基本数据格式的基本操作 hash [], get(..), None.. 获得uniq list

发布时间: 2023-10-05 00:37:00

refer to: https://flexiple.com/python/check-if-key-exists-in-dictionary-python

基本跟ruby 一样

a = {'one': 1, 'two': 2} 

a['one']  # => 1

a.get('not-exist-key')   # =>  None

a['not-exist-key']  # => 报错

把一个list转换为uniq list:

a = "123"

set(list(a))

Back