在 python 中的一个变量中,我得到如下列表:
stop_address_type = ['1','2']
在另一个变量中,我越来越像:
stop_facility_name = ['A','B']
结果:这就是我真正想要的
stop_address_type = ['1','2']
stop_facility_name = ['','B']
另一种情况,如:
stop_address_type = ['2','1']
stop_facility_name = ['A','']
我真正想要的是当我在 stop_address_type 变量中获得 1 值时,我想清空列表 stop_facility_name 的相同值,例如:
您可以通过这样的方法传递列表:
stop_address_type = ['1', '2']
stop_facility_name = ['A', 'B']
def check_facility_name(address_typ_list, facility_name_list):
for i, obj in enumerate(address_typ_list):
if obj == '1':
facility_name_list[i] = ""
print(stop_facility_name)
# ['A', 'B']
check_facility_name(stop_address_type, stop_facility_name)
print(stop_facility_name)
# ['', 'B']
无论 1 出现在 adress_type_list 的何处,这都会为您提供所需的输出
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句