[파이썬기초] 주민번호 뒷자리를 별표(*)로 변경하기

2020. 4. 2. 14:09노트/Python : 프로그래밍

data="""
kim 950101-1234567
lee 970202-2345678
"""

result=[]
for line in data.split("\n"):
    word_res=[]
    for word in line.split(" "):
        if len(word)==14 and word[:6].isdigit() and word[7:].isdigit():
            w=word[0:6]+"-"+"*******"
            word_res.append(w)
    result.append(" ".join(word_res))  
print("\n".join(result))