def union(list_a,list_b):
for i in list_b:
if i in list_a:
pass
else:
list_a.append(i)
def main():
list_a = ['a','b','c']
list_b = ['c','d','e',]
union(list_a,list_b)
print(list_a)
if __name__ == '__main__':
main()
A,B均按递增排列,合并AB为C并且还是递增
def MergeList(list_a,list_b,list_c):
la_len = len(list_a)-1
lb_len = len(list_b)-1
i=j=0
while (i<= la_len) and (j<=lb_len):
print(i)
ai = list_a[i]
print(ai)
bj = list_b[j]
if ai <= bj:
list_c.append(list_a[i])
i+=1
print('2行',i,j)
else:
list_c.append(list_b[j])
j+=1
while i<=la_len:
list_c.append(list_a[i])
i+=1
while j<=lb_len:
list_c.append(list_b[j])
j+=1
def main():
list_a = [1,2,3]
list_b = [3,4,5]
list_c = []
MergeList(list_a,list_b,list_c)
print(list_c)
if __name__ == '__main__':
main()