L=[]
for each in zip(L1,L2):
L.extend(,each])
if len(L1)>len(L2):
for i in range(len(L2),len(L1)):
L.append(L1)
else:
for i in range(len(L1),len(L2)):
L.append(L2)
print(L)
L1=['A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7']
L2=['B0', 'B1', 'B2', 'B3']
merge(L1,L2)
lst1 = ['A0', 'A1', 'A2', 'A3', 'A4', 'A5']
lst2 = ['B0', 'B1', 'B2', 'B3', 'B4', 'B5']
lst3 = ['A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7']
lst4 = ['B0', 'B1', 'B2', 'B3']
def merge(lsta, lstb):
newlist = []
a = len(lsta)
b = len(lstb)
for i in zip(lsta, lstb):
newlist.extend(, i])
if a > b:
newlist.extend(lsta)
if b > a:
newlist.extend(lstb)
print(newlist)
merge(lst1, lst2)
merge(lst3, lst4)
a=['A0','A1','A2','A3','A4','A5','A6','A7','A8','A9','A10']
b=['B0','B1','B2','B3','B4','B5']
lena=len(a)
lenb=len(b)
lenmin=min(lena,lenb)
lis=[]
for i in range(lenmin):
lis.append(a)
lis.append(b)
if lena!=lenb:
if lena>lenb:
for i in range(lenb,lena):
lis.append(a)
else:
for i in range(lena,lenb):
lis.append(b)
list1 = list()
list2 = list()
while True:
temp = input('请逐字输入第1个列表元素,并以"#"结束:')
if temp != '#':
list1.append(temp)
else:
print(list1)
break
while True:
temp = input('请逐字输入第2个列表元素,并以"#"结束:')
if temp != '#':
list2.append(temp)
else:
print(list1)
break
i = min(len(list1), len(list2))
list3 = list1 if len(list1) >len(list2) else list2
list4 = list(zip(list1, list2))
list5 =list()
for j in range(i):
list5 = list5 + list(list4)
list5 = list5 + list3
print (list5)
def merge(ls1, ls2):
ls1.extend(ls2)
ls1.sort(key=lambda x: (x, x))
return ls1
ls1 = ['B0', 'B1', 'B2', 'B3', 'E1', 'E9']
ls2 = ['A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'C1', 'C2']
print(merge(ls1, ls2)) 本帖最后由 holiday_python 于 2020-7-31 14:06 编辑
def merge(A, B):
c = []
for i in len(A):
for j in len(B):
if i == j:
c.append(A)
c.append(B)
elif i > j:
c.expand(A)
elif i < j:
c.expand(B)
return c 学习一下 1 学习
页:
1
[2]