acclivity

pyCleanPhoneNumbers

Mar 29th, 2022 (edited)
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. # Clean and standardise a list of phone numbers
  2.  
  3. def clean_numbers(nlist):
  4.     newlist = []
  5.     for x, ins in enumerate(nlist):
  6.         outs, x = "", -1
  7.         while len(outs) < 10:
  8.             if ins[x].isdigit():
  9.                 outs = ins[x] + outs
  10.             x -= 1
  11.         newlist.append("+92" + outs)
  12.     return newlist
  13.  
  14.  
  15. number_list = [' 03336482191', '3017651141', ' 0335-7588669', '923009772069']
  16. print(clean_numbers(number_list))
  17.  
  18. # Output:
  19. # ['+923336482191', '+923017651141', '+923357588669', '+923009772069']
  20.  
Add Comment
Please, Sign In to add comment