set和dict

Posted richiewlq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了set和dict相关的知识,希望对你有一定的参考价值。

dict属于mapping类型

from collections.abc import Mapping,MutableMapping
from collections.abc import __all__

# dict 属于Mapping类型

a = 
print(isinstance(a,MutableMapping))

copy 浅拷贝

a = 
    "liming1":"company":"tencent1",
    "liming2":"company":"tencent2",


# clear
""" D.clear() -> None.  Remove all items from D. """
# a.clear()

#copy 浅拷贝
""" D.copy() -> a shallow copy of D """
new_dict = a.copy()
new_dict[liming1][company] = tencent3

print(a)
print(new_dict)

###########
liming1: company: tencent3, liming2: company: tencent2
liming1: company: tencent3, liming2: company: tencent2

fromkeys

# fromkeys
new_list = [liming1,liming2]

new_dict = dict.fromkeys(new_list,company:tencent)

print(new_dict)

update

# update

new_dict.update(lisa:"company":"tencent2")
new_dict.update(liming2:"company":"tencent2")
new_dict.update(jenny=company:beijing)
new_dict.update([(jenny,company:shanghai)])
print(new_dict)

 

以上是关于set和dict的主要内容,如果未能解决你的问题,请参考以下文章

Python-字典dic和集合set

python的dict和set

python基础之dict和set

写了个条目录入的脚本

python 5

Python *Mix_w5