Tell me about this code execution mechanism

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

data = """
park 800905-1049118
kim 700905-1059119
"""

result = []
For line in data.split("\n"): #where data is divided by line.
    word_result = []
    For word in line.split("): #Divide data by line by space.
        if len(word) ==14 and word[:6].isdigit() and word[7:].Isdigit(): Change the resident number data among the data in #word.
            word = word[:6] + "-" + "*******"
        Word_result.append(word) #Put the resident number changed with the name into word_result.
    result.append(".join(word_result)) #If you combine it here, you will combine it with result-> park 800905-****kim 700905-****kim in one line

print("\n".join(result)# I don't know how it's divided by line here.

#I don't know how this happens when the results come like this. I think it's going to be 4 lines after you combine them
park 800905-*******
kim 700905-*******

Please look at the comments

python

2022-09-20 16:32

1 Answers

data = """
park 800905-1049118
kim 700905-1059119
"""

result = []
For line in data.split("\n"): #where data is divided by line.
    word_result = []
    For word in line.split("): #Divide data by line by space.
        if len(word) ==14 and word[:6].isdigit() and word[7:].Isdigit(): Change the resident number data among the data in #word.
            word = word[:6] + "-" + "*******"
        Word_result.append(word) #Put the resident number changed with the name into word_result.
    result.append(".join(word_result)) #If you combine it here, you will combine it with result-> park 800905-****kim 700905-****kim in one line

print("\n".join([ str(i) + l for i, line enumerate(result)))) # I don't know how it's divided by line here.

If you run it like this, you can't see it, but you can print four lines.


2022-09-20 16:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.