Advertisement
davide1409

inserisci

Nov 24th, 2019
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. def Inserisci(L,n1,n2):
  2. #@param L: list of integers
  3. #@param n1: int
  4. #@param n2: int
  5. #@return list of integers
  6.  
  7.   new_l = L[:]
  8.  
  9.   if not L.count(n1):
  10.     return L
  11.    
  12.   else:
  13.     lung = len(L)
  14.     for i in range(lung):
  15.       if L[i] == n1:
  16.         if i+1==lung:
  17.           new_l.append(n2)
  18.         else:      
  19.           new_l.insert(i+1,n2)
  20.    
  21.     return new_l
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement