简体   繁体   中英

How to set attributes of objects in a multi-dimensional array in python?

Given two multi-dimensional arrays, the first multi-dimensional array containing the values and the second multi-dimensional array containing the objects. How to set attributes of all the objects in the second array such that the attributes are the values from the first multi-dimensional array?

md_array_1 = [[[14, 15, 18], [24, 21]], [[12, 13, 21], [15, 14]]]
md_array_2 = [[[obj_1, obj_2, obj_3], [obj_4, obj_5]], [[obj_6, obj_7, obj_8], [obj_9, obj_10]]]

obj_1.value = 14
obj_2.value = 15
obj_3.value = 18
for sublist1, sublist2 in zip(md_array_1, md_array_2):
   for sublist_1, sublist_2 in zip(sublist1, sublist2):
       for val, obj in zip(sublist_1, sublist_2):
           obj.value = val

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM