'''
实现两个list元素1对1拼接
实现结果:1-8-314,99-2-6332
'''
def main():
list1 = ['0108', '9902', '207']
list2 = ['314', '6332', '0305']
# list1 = ['None']
# list2 = ['None']
# list1 = []
# list2 = []
list4 = []
for i in range(0, len(list1)): #len(list1)获取列表长度
list1_len1 = len(list1[i]) #元素长度
try:
if list1_len1 == 4 and 'None' not in list1:
l1_build = list1[i][:2].lstrip("0") # 去除前面的0
l1_unit = list1[i][3]
l2_room = list2[i]
list3 = l1_build + '-' + l1_unit + '-' + l2_room
elif list1_len1 == 3:
l1_build = list1[i][:1]
l1_unit = list1[i][2]
l2_room = list2[i]
list3 = l1_build + '-' + l1_unit + '-' + l2_room
elif 'None' in list1:
list3 = ''
if list3 != '':
list4.append(list3)
except:
break
print("list4:", ','.join(list4))
if __name__=="__main__":
main()
12-08
6031
07-18
5033