0

As I can solve this exercise without having ...

.. to add the item None of the end list and continue to use iter and next from random import randint A = [x for x in range(1,9) if randint(0,2) == 1]+[None] B = [x for x in range(1,9) if x not in A]+[None] print(A,B) iA, iB = iter(A), iter(B) i,j = next (iA), next(iB) C = [] while (i != None and j != None): if (i < j): C.append(i) i = next(iA) else: C.append(j) j = next(iB) for i in iA: C.append(i) for j in iB: C.append(j) C.remove(None) print (C)

17th Mar 2017, 10:32 PM
Javier I. Rivera R.
Javier I. Rivera R. - avatar
2 Respuestas
+ 3
If you do it this way, not using None requires you to use the try/except construct to catch the StopIteration exception that is raised after the end of the iteration. So you need to learn how to do that
17th Mar 2017, 10:42 PM
Amaras A
Amaras A - avatar
+ 2
@Amaras, Ready !!!.. Thanks you.. https://code.sololearn.com/c1CHWgpJRgYI
17th Mar 2017, 11:07 PM
Javier I. Rivera R.
Javier I. Rivera R. - avatar