-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathMasking Personal Information.py
59 lines (40 loc) · 1.42 KB
/
Masking Personal Information.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Solution:
def maskPII(self, s: str) -> str:
res=''
if '@' in s:
l=s.split('@')
a=l[0]
b=l[1]
c=b.split('.')
res=a[0].lower()+'*'*5+a[-1].lower()+'@'+c[0].lower()+'.'+c[1].lower()
return res
else:
l=0
res=''
flag=False
f=False
c=0
for i in range(len(s)-1,-1,-1):
if s[i]=="(" or s[i]==')' or s[i]=='-' or s[i]=='+' or s[i]==' ':
continue
if f==True:
c+=1
continue
if flag==False:
res=s[i]+res
else:
res='*'+res
if l==3 or l==6:
if l==3:
flag=True
res='-'+res
l+=1
if len(res)==12:
f=True
if c==1:
res='+*-'+res
elif c==2:
res="+**-"+res
elif c==3:
res="+***-"+res
return res