当前位置:网站首页>Zip and Items() difference

Zip and Items() difference

2022-06-12 06:09:00 Just change your name

zip Is a pointer that rearranges variables , from zip The modification of the extracted object will take effect in the original variable .
.item() What is taken out is the value , from .items() The modification of the extracted items will not affect the original variables .

import json

pth = r"F:\vscode_files\project\segment_side\segment_side_example-18.json"

f = open(pth)
dict_img_id_seg = {}
seg_json = json.load(f)
anno = seg_json["annotations"][0]
dict_img_id_seg[anno["image_id"]] = [anno["category_id"], anno["segmentation"]]
print(dict_img_id_seg)

for k, v in dict_img_id_seg.items():
    print(type(k))
    print(type(v))
    v = 1
print(type(dict_img_id_seg.items()))
print(dict_img_id_seg)

list1 = [dict_img_id_seg]
list2 = [1]
for one, two in zip(list1, list2):
    print(type(one))
    print(type(two))
    one[2400] = two
    two = 2
print(type(zip(list1, list2)))
print(list1)
print(list2)

output:

{2400: [11, [[144.7, 134.2, 185.5, 132.3, 183.9, 149.6, 142.1, 150.0, 141.7, 143.0, 144.7, 137.3]]]}
<class 'int'>
<class 'list'>
<class 'dict_items'>
{2400: [11, [[144.7, 134.2, 185.5, 132.3, 183.9, 149.6, 142.1, 150.0, 141.7, 143.0, 144.7, 137.3]]]}
<class 'dict'>
<class 'int'>
<class 'zip'>
[{2400: 1}]
[1]
原网站

版权声明
本文为[Just change your name]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120602569841.html