Python Resident Number Covering Function

Asked 2 years ago, Updated 2 years ago, 17 views

From Python, {person name: resident number} Dictionary of the same form

It is a question of expressing * after the number (8th digit) that is always expressed in the function.

I want to use it as a function, but I want to make something that works the same even if the dictionary's item increases

security_number = {
    "old_man" : "911210-1234567",
    "young_man" : "011220-3123456",
    "old_woman" : "891103-2513455",
    "young_woman" : "040302-4912911"}

Dictionary of this kind

    "old_man" : "911210-1******",
    "young_man" : "011220-3******",
    "old_woman" : "891103-2******",
    "young_woman" : "040302-4******"

I want to make a function that comes out like this

I think they use "for" and "**" I don't know how to use dictionaries.

python

2022-09-20 11:00

1 Answers

a = {
    "old_man" : "911210-1234567",
    "young_man" : "011220-3123456",
    "old_woman" : "891103-2513455",
    "young_woman" : "040302-4912911"
}

for i in a:
    a[i] = a[i][:8] + '*' * 6
print(a)
>> {'old_man': '911210-1******', 'young_woman': '040302-4******', 'young_man': '011220-3******', 'old_woman': '891103-2******'}


2022-09-20 11:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.