In the following code user enters N pair of inputs and each time that users enter value 2, the most recent pair (not integer) should be deleted and list should be updated. Assume the input list is lis=[(1,97),2,(1,20),2,(1,26),(1,20),2]. Therefore, the final updated output should be lis=[(1,26)]. My code store all the pairs in lis and does not remove elements. Please note that I need my own code be revised not a totally different code.
N = int(input())
lis=[]
for i in range(N):
b = (input().split())
if len(b)==2:
lis.append(b)
if b == 2:
del lis[0]
lis.append(lis)
Aucun commentaire:
Enregistrer un commentaire